未初始化的常量ApplicationController :: PermittedParams强参数

时间:2015-04-16 14:11:32

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4

不知道我哪里出错,我搜索了很多谷歌搜索,但也不知道我做错了什么。

我的应用控制器

class ApplicationController < ActionController::Base

helper_method :clipboard, :current_user, :signed_in?, :permitted_params

def permitted_params
  @permitted_params ||= PermittedParams.new(params, current_user)       
end

我的模型Permitted_Param.rb

class PermittedParams < Struct.new(:params, :current_user)
   %w{folder group share_link user user_file}.each do |model_name|
     define_method model_name do
       params.require(model_name.to_sym).permit(*send("#{model_name}_attributes"))
     end   
   end

   def folder_attributes
     [:name]   
   end

   def group_attributes
     [:name]   
   end

   def share_link_attributes
     [:emails, :link_expires_at, :message]   
   end

   def user_attributes
     if current_user && current_user.member_of_admins?
       [:name, :email, :password, :password_confirmation, { :group_ids => [] }]
     else
       [:name, :email, :password, :password_confirmation]
     end   
   end

   def user_file_attributes
     [:attachment, :attachment_file_name]   
   end 
end

日志

  

在2015-04-16 19:37:02 +0530左开始获取127.0.0.1的“/”   ActiveRecord :: SchemaMigration Load(0.6ms)SELECT   “schema_migrations”。* FROM“schema_migrations”处理方式   FoldersController #index as HTML User Load(0.5ms)SELECT“users”。*   FROM“users”WHERE“users”。“is_admin”=?限制1 [[“is_admin”,“t”]]   重定向到http://localhost:3000/admins/new过滤器链停止为   :require_admin_in_system呈现或重定向已完成302找到   207ms(ActiveRecord:1.0ms)开始获取127.0.0.1的GET“/ admins / new”   2015-04-16 19:37:03 +0530由AdminsController处理#new为HTML
  用户负载(0.2ms)SELECT“users”。* FROM“users”WHERE   “用户”。“is_admin”=? LIMIT 1 [[“is_admin”,“t”]]已渲染   布局/应用程序中的admins / new.html.erb(331.3ms)用户加载   (0.4ms)SELECT“users”。* FROM“users”WHERE“users”。“id”IS NULL   LIMIT 1渲染共享/ _header.html.erb(21.3ms)CACHE(0.1ms)   SELECT“users”。* FROM“users”WHERE“users”。“id”IS NULL LIMIT 1
  渲染的共享/ _menu.html.erb(8.4ms)已渲染   shared / _footer.html.erb(0.8ms)在1789ms完成200 OK(浏览次数:   1707.5ms | ActiveRecord的:       1.7ms)       在2015-04-16 19:37:19开始POST“/ admins”for 127.0.0.1 +0530由AdminsController处理#create as HTML参数:   { “UTF8”=&gt; “中✓”,   “authenticity_token”=&gt; “中5VPDMdM6Cny63T00tcgU55ukkDD9XChTQwWjAJ7IUZ0ELh6D5c7UhbpbOKdQ3atdaNIaBVk5AxctcC0j09pcvQ ==”,   “user”=&gt; {“name”=&gt;“ChiragArya”,“email”=&gt;“edwardmaya008@gmail.com”,   “password”=&gt;“[FILTERED]”,“password_confirmation”=&gt;“[FILTERED]”},   “commit”=&gt;“创建管理员帐户”}用户加载(0.4ms)SELECT   “users”。* FROM“users”WHERE“users”。“is_admin”=?限制1   [[“is_admin”,“t”]]在26ms内完成500内部服务器错误   (ActiveRecord:0.4ms)       NameError(未初始化的常量ApplicationController :: PermittedParams):
  app / controllers / application_controller.rb:26:in permitted_params'
app/controllers/admins_controller.rb:10:in
        呈现/home/chirag/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_source.erb   (54.9ms)已呈现   /home/chirag/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb(35.3ms)呈现   /home/chirag/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb   (10.4ms)呈现   /home/chirag/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb   在救援/布局(227.5ms)内

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,在将我的强参数函数名称重命名为controllername _ params

之后我解决了这个问题

我不知道提到哪里,但我很想知道。