web-dev-qa-db-ja.com

Rails 4認証

Rails 4 ??.

.rvm/gems/Ruby-2.0.0-p0/gems/activemodel-4.0.0.beta1/lib/active_model/deprecated_mass_assignment_security.rb:14:in `attr_accessible': `attr_accessible` is extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or add `protected_attributes` to your Gemfile to use old one. (RuntimeError)
    from /home/leapfrog/projects/kathloc/app/models/user.rb:8:in `<class:User>'
    from /home/leapfrog/projects/kathloc/app/models/user.rb:1:in `<top (required)>'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:423:in `load'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:423:in `block in load_file'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:615:in `new_constants_in'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:422:in `load_file'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:323:in `require_or_load'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:462:in `load_missing_constant'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:183:in `const_missing'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:226:in `const_get'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:226:in `block in constantize'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:224:in `each'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:224:in `inject'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:224:in `constantize'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:534:in `get'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:565:in `constantize'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/devise-1.5.4/lib/devise.rb:261:in `get'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/devise-1.5.4/lib/devise/mapping.rb:77:in `to'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/devise-1.5.4/lib/devise/mapping.rb:72:in `modules'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/devise-1.5.4/lib/devise/mapping.rb:89:in `routes'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/devise-1.5.4/lib/devise/mapping.rb:156:in `default_used_route'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/devise-1.5.4/lib/devise/mapping.rb:66:in `initialize'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/devise-1.5.4/lib/devise.rb:291:in `new'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/devise-1.5.4/lib/devise.rb:291:in `add_mapping'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/devise-1.5.4/lib/devise/Rails/routes.rb:193:in `block in devise_for'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/devise-1.5.4/lib/devise/Rails/routes.rb:192:in `each'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/devise-1.5.4/lib/devise/Rails/routes.rb:192:in `devise_for'
    from /home/leapfrog/projects/kathloc/config/routes.rb:2:in `block in <top (required)>'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/routing/route_set.rb:320:in `instance_exec'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/routing/route_set.rb:320:in `eval_block'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/routing/route_set.rb:298:in `draw'
    from /home/leapfrog/projects/kathloc/config/routes.rb:1:in `<top (required)>'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:222:in `load'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:222:in `block in load'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:213:in `load_dependency'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:222:in `load'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/railties-4.0.0.beta1/lib/Rails/application/routes_reloader.rb:40:in `block in load_paths'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/railties-4.0.0.beta1/lib/Rails/application/routes_reloader.rb:40:in `each'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/railties-4.0.0.beta1/lib/Rails/application/routes_reloader.rb:40:in `load_paths'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/railties-4.0.0.beta1/lib/Rails/application/routes_reloader.rb:16:in `reload!'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/railties-4.0.0.beta1/lib/Rails/application/routes_reloader.rb:26:in `block in updater'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/file_update_checker.rb:75:in `call'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/file_update_checker.rb:75:in `execute'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/railties-4.0.0.beta1/lib/Rails/application/routes_reloader.rb:27:in `updater'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/railties-4.0.0.beta1/lib/Rails/application/routes_reloader.rb:7:in `execute_if_updated'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/railties-4.0.0.beta1/lib/Rails/application/finisher.rb:69:in `block in <module:Finisher>'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/railties-4.0.0.beta1/lib/Rails/initializable.rb:30:in `instance_exec'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/railties-4.0.0.beta1/lib/Rails/initializable.rb:30:in `run'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/railties-4.0.0.beta1/lib/Rails/initializable.rb:55:in `block in run_initializers'
    from /home/leapfrog/.rvm/rubies/Ruby-2.0.0-p0/lib/Ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
    from /home/leapfrog/.rvm/rubies/Ruby-2.0.0-p0/lib/Ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
    from /home/leapfrog/.rvm/rubies/Ruby-2.0.0-p0/lib/Ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
    from /home/leapfrog/.rvm/rubies/Ruby-2.0.0-p0/lib/Ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
    from /home/leapfrog/.rvm/rubies/Ruby-2.0.0-p0/lib/Ruby/2.0.0/tsort.rb:180:in `each'
    from /home/leapfrog/.rvm/rubies/Ruby-2.0.0-p0/lib/Ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
    from /home/leapfrog/.rvm/rubies/Ruby-2.0.0-p0/lib/Ruby/2.0.0/tsort.rb:148:in `tsort_each'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/railties-4.0.0.beta1/lib/Rails/initializable.rb:54:in `run_initializers'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/railties-4.0.0.beta1/lib/Rails/application.rb:213:in `initialize!'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/railties-4.0.0.beta1/lib/Rails/railtie/configurable.rb:30:in `method_missing'
    from /home/leapfrog/projects/kathloc/config/environment.rb:5:in `<top (required)>'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:228:in `require'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:228:in `block in require'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:213:in `load_dependency'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:228:in `require'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/railties-4.0.0.beta1/lib/Rails/application.rb:187:in `require_environment!'
    from /home/leapfrog/.rvm/gems/Ruby-2.0.0-p0/gems/railties-4.0.0.beta1/lib/Rails/commands.rb:45:in `<top (required)>'
    from bin/Rails:4:in `require'
    from bin/Rails:4:in `<main>'
18
Amrit Dhungana

Rails-4ActiveModel::MassAssignmentSecurityはActiveModelから削除されました。しかし、deviseはattr_accessibleを使用するため、それを使用するには、次のgemをur Gemfileに追加して、もう一度ロードしてみます。

gem 'protected_attributes'

編集:

現在、deviseはRails-4をサポートしています。これをGemfileに含めます。

gem 'devise', '3.0.0.rc'
26
Sagar Bommidi

Edit:Rails 4:をサポートするDeviseバージョンがあります Devise 3.0.0.rc

以前の答え:それをうまく機能させるために私が最後にやったことは...

  1. Gemfileの場合:gem 'devise', github: 'plataformatec/devise', branch: 'Rails4'

  2. 生成されたモデルで、attr_accessibleスタッフ。

  3. Attr_accessibleの代わりにDeviseの強力なパラメーターを有効にします。そのためには、そのコンテンツで新しいinitiliazerを作成します。

    DeviseController.class_eval do
      def resource_params
        unless params[resource_name].blank?
          params.require(resource_name).permit(:email, :password, :password_confirmation, :remember_me)
        end
      end
    end
    
14
jipiboily

プロジェクトのdeviseでattr_accessibleを使用する代わりに、以下の方法でAccesssiblesを使用してください-

attr_accessible:email、:password、:password_confirmation、:remember_meのように、セキュリティ上の理由からプライベートメソッドで変換できます。

private

def user_params  
  params.require(:user).permit(:email, :password, :password_confirmation, :remember_me)

end
4
Amit Suroliya

それは本当にあなたが宝石に何をする必要があるかによります。多くのオプションがあり、Deviseは間違いなく一番上にあります。 Thoughtbot( https://github.com/thoughtbot/clearance )によるクリアランスをお勧めします。十分にテストされており、頻繁に更新されています。私にとって、コア認証機能が必要なときに非常に役立ちました。Deviseのような宝石に付属する他のすべてのものではありませんでした。

1
Samwise

deviseで問題が発生している場合は、「Authlogic」を試すことも認証に適した逸品です。

サポートされている最新バージョンであるgem 'authlogic' '〜3.2.0'を使用できますRails 4.0

Rubyツールボックスには、最も人気のあるもののリストがあります。 http://Ruby-toolbox.com/categories/Rails_authentication.html

1
Gaurav Sharma

Rails 4.のデバイスの問題を修正しました。手間をかけずに実装できます。

gemfileにgem 'devise'を追加してバンドルするだけです。

ありがとう

0
Shoaib Malik

GemFileにgem "devise"、 "〜> 3.0.0.rc"と書き込みます。そして、ここで提供される指示に従ってください https://github.com/plataformatec/devise

あなたの問題が解決されることを願っています。

0