Rails 4,gem protected_attributes,RefineryCMS和Devise之间的冲突

时间:2015-03-19 03:03:01

标签: ruby-on-rails ruby devise refinerycms

我们刚开始使用新的Rails 4网站,我们决定将RefineryCMS用于其中一些网站。然后我还安装了Devise,用于RefineryCMS未涵盖的网站部分。

因为一些RefineryCMS插件是为Rails 3编写的,所以我们必须使用protected_attributes gem,它提供了一个平滑的升级路径。

我们的用户模型最初看起来像这样:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable         
end

但是,当我在注册#new时填写表单时,我收到了2个验证错误:

Email can't be blank

Password can't be blank

但是我已经填满了。所以我想也许这是一个批量分配的问题。所以我将其添加到用户模型中:

  attr_accessible :email, :password, :password_confirmation, 
                  :remember_me, :first_name, :last_name, :profile_name

所以现在我有:

class User < ActiveRecord::Base

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable         

  attr_accessible :email, :password, :password_confirmation, 
                  :remember_me, :first_name, :last_name, :profile_name

end

这解决了密码问题 - 我不再收到有关密码为空的错误。但我仍然收到有关电子邮件空白的错误。

有关我需要做什么才能收到电子邮件的建议吗?

(有一段时间与该字段中的第二个登录表单存在冲突,该表单出现在Javascript灯箱中,但我已将其删除。)

从开发日志中:

Started GET "/users/sign_up" for 127.0.0.1 at 2015-03-18 23:09:25 -0400
Processing by Devise::RegistrationsController#new as HTML
  Rendered devise/shared/_links.html.erb (0.3ms)
  Rendered devise/registrations/new.html.erb within layouts/application (3.6ms)
  Rendered vendor/bundle/ruby/2.1.0/bundler/gems/refinerycms-11f8d1eeb45e/core/app/views/refinery/_html_tag.html.erb (0.1ms)
  Rendered refinery/_site_bar.html.erb (0.3ms)
Completed 200 OK in 25ms (Views: 22.6ms | ActiveRecord: 0.0ms)


Started POST "/users" for 127.0.0.1 at 2015-03-18 23:09:41 -0400
Processing by Devise::RegistrationsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"lERPLieT6htcLhC8yqBq00/6mz2AAfYzrFjTFEJ2lbg=", "user"=>{"email"=>"lawrence@krubner.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
Unpermitted parameters: email
   (0.1ms)  begin transaction
   (0.1ms)  rollback transaction
  Rendered devise/shared/_links.html.erb (0.4ms)
  Rendered devise/registrations/new.html.erb within layouts/application (6.2ms)
  Rendered vendor/bundle/ruby/2.1.0/bundler/gems/refinerycms-11f8d1eeb45e/core/app/views/refinery/_html_tag.html.erb (0.1ms)
  Rendered refinery/_site_bar.html.erb (0.3ms)
  Rendered _login.html.erb (0.1ms)
Completed 200 OK in 141ms (Views: 40.7ms | ActiveRecord: 0.2ms)

我完全按照这里的建议:

rails-4-devise-mongodb-unpermitted-parameters-using-custom-properties

这对我没有任何改变。

我认为我没有自定义属性,但我们安装RefineryCMS确实如此。我不确定它对用户模型的想法是否与Device试图做的有冲突。我如何测试以查看正在使用的型号?该路由属于设备,所以我假设设备代码将控制这种情况。

[UPDATE]

嗯,好吧,这至少让我有了一个不同的错误:

def configure_permitted_parameters
  devise_parameter_sanitizer.for(:sign_up) do |u|
    u.permit(:email,:password,:password_confirmation)
  end
end

现在我遇到了路由错误。

0 个答案:

没有答案