Tag: devise

如何在rails迁移中将数据从一个表移动到另一个表?

我已经使用这些资源设置了一个rails网站: 用户(设计)作者 我已经意识到我需要将所有作者移到用户表中,因为我现在正在为这些用户设置角色作为作者。 目前我已经尝试了以下迁移,但没有任何工作,也没有数据传输到users表: class MoveAuthorsColumnDataToUsersTable author.name.downcase.gsub(‘ ‘,”), :encrypted_password => “”, :email => “”, :avatar_file_name => author.avatar_updated_at, :avatar_content_type => author.avatar_content_type, :avatar_file_size => author.avatar_file_size, :avatar_updated_at => author.avatar_updated_at, :role_id => “3” ) end end end 我在控制器中有一个带有属性的作者模型设置,我最终会将所有作者模型关系转移给用户。 author.rb模型: class Author { :large => “980×760”, :medium => “300×300>”, :thumb => “100×100>” }, :default_url => “/images/:style/missing.png” validates_attachment_content_type :avatar, :content_type => […]

skip_before_filter用于设计的“登录”操作

我可以这样做,在我需要的某个控制器中跳过调用“authenticate_user”: class ApplicationController before_filter :authenticate_user! end class MyController < ApplicationController skip_before_filter :authenticate_user! end 我想调用skip_before_filter来设计skip_before_filter的“login”操作,我不想重写任何其他内容。 我怎样才能做到这一点?

设计:如果没有用户,则重定向以注册页面而不是登录

如果没有用户在场,我希望将请求重定向到“注册”页面而不是“登录”页面。 所以,为此,我重写了authenticate_user! 应用程序控制器中的方法: class ApplicationController < ActionController::Base protect_from_forgery with: :exception before_action :authenticate_user! protected def authenticate_user! redirect_to new_user_registration_path unless User.any? end end 这里的问题是页面没有正确重定向。 该请求将被无限期地重定向到注册页面,即请求未完成。 在rails服务器控制台上显示: Filter chain halted as :authenticate_user! rendered or redirected Completed 302 Found in 0ms (ActiveRecord: 0.0ms)

迁移失败:PG :: ProtocolViolation Rails

我刚刚更新到rails4并意识到我的db角色和数据库不知何故没有设置。 所以我删除了数据库并重新创建了app_development数据库和角色。 现在我正在尝试运行rake db:migrate并且它失败并出现以下错误: == DeviseCreateUsers: migrating ============================================== — create_table(:users) -> 0.0081s — add_index(:users, :email, {:unique=>true}) -> 0.0031s — add_index(:users, :reset_password_token, {:unique=>true}) -> 0.0030s == DeviseCreateUsers: migrated (0.0144s) ===================================== rake aborted! An error has occurred, this and all later migrations canceled: PG::ProtocolViolation: ERROR: bind message supplies 1 parameters, but prepared statement “a1” requires 0 : […]

Rails设计不会将额外的输入字段保存到数据库

我在使用Devise gem将额外的用户字段值插入数据库时​​遇到问题。 我错过了什么? 我正在使用 ruby 2.1.5p273 Rails 4.1.8 这是我的user.rb模型 class User [:login] attr_accessor :login, :name, :last_name, :address, :post_number, :city, :mobile validates :username, presence: true, length: {maximum: 25}, :uniqueness => { :case_sensitive => false } validates :name, presence:true validates :last_name, presence:true validates :address, presence:true validates :post_number, presence:true validates :city, presence:true validates :country, presence:true validates :mobile, presence:true […]

Devise无法登录Google Chrome

我正在使用Devise gem在Ruby on Rails Web应用程序上进行用户身份validation。 这个过程非常直接。 但是,在添加Nginx和ssl证书后,我可以在Mozilla Firefox中登录但无法登录Google Chrome的应用程序。 到目前为止,我能找到的唯一跟踪是我的环境日志文件中的这几行: Processing by Devise::SessionsController#create as HTML Parameters: {“utf8″=>”✓”, “authenticity_token”=>”==”, “user”=>{“email”=>”email@test.com”, “password”=>”[FILTERED]”, “remember_me”=>”0”}, “commit”=>”LOG IN”} HTTP Origin header (https://) didn’t match request.base_url (: https://:80) 我的Nginx配置为/ location / { proxy_pass http://127.0.0.1:3000; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_set_header X-Forwarded-Proto: $scheme; } 注意:如果我删除了proxy_set_header […]

将Drupal用户帐户导入Rails,无需用户更改密码

我想将一系列Drupal用户帐户导入到新的 Rails项目中。 我在Rails中使用Devise进行用户身份validation。 我希望能够将Drupal中的加密密码导入到rails中,以便用户在迁移网站时获得无缝体验。 关于如何做到这一点的任何想法?

添加值名称以设计时出错

我试图将值名称添加到设计中时出错,我认为所有事情都做了所有工作,但它不起作用。 NoMethodError in Devise/registrations#new undefined method `name’ for # 这是我的用户模型: class User 165, :filetype => :png, :rating => ‘R’ # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable validates :email, :username, :presence => true, :uniqueness => true # Setup accessible […]

使用多个“用户”模型获取Paper_trail + Rails_admin +设计

我正在开发Rails 3中的应用程序,目前我使用Devise作为登录,Rails_admin作为管理面板,Paper_trail跟踪“用户”模型所做的所有更改…问题是我有两个用户模型,User和Admin。 因此,rails_admin.rb(initiliazer)中的一行代码用于设置Paper_trail以跟踪历史记录: config.audit_with :paper_trail, User 有没有办法让用户和管理员进行paper_trail监视器更改,还是只能跟随一个模型? 我注意到,即使它设置为这样,并且我在Rails_admin中作为管理员进行了更改,更改说它是由用户创建的,其ID与进行更改的管理员相同。

如何创建一个自动将用户登录到devise / rails的链接?

我正在尝试让已注册用户在我的网站上执行某些操作,因此我希望通过电子邮件直接发送此操作的链接。 问题是我希望在点击该链接时自动登录。 我可以做一些明显的事情,比如创建一个独特的令牌并通过url mysite.com/my_funky_action?login_bypass_token=af123fa127ba32传递它,但这在我看来是一个“以前解决过很多次”的问题。 那么,使用rails / devise有一个简单的方法可以做到这一点吗? 我搜索了设计文档但没有成功。