0
votes

Don't know where i'm getting wrong, i have searched a lot googling and also in SO but i don't understand what i am doing wrong.

My Application Controller

class ApplicationController < ActionController::Base

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

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

My Model 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

Log

Started GET "/" for 127.0.0.1 at 2015-04-16 19:37:02 +0530
ActiveRecord::SchemaMigration Load (0.6ms) SELECT "schema_migrations".* FROM "schema_migrations" Processing by FoldersController#index as HTML User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."is_admin" = ? LIMIT 1 [["is_admin", "t"]] Redirected to http://localhost:3000/admins/new Filter chain halted as :require_admin_in_system rendered or redirected Completed 302 Found in 207ms (ActiveRecord: 1.0ms) Started GET "/admins/new" for 127.0.0.1 at 2015-04-16 19:37:03 +0530 Processing by AdminsController#new as HTML
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."is_admin" = ? LIMIT 1 [["is_admin", "t"]] Rendered admins/new.html.erb within layouts/application (331.3ms) User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT 1 Rendered shared/_header.html.erb (21.3ms) CACHE (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT 1
Rendered shared/_menu.html.erb (8.4ms) Rendered shared/_footer.html.erb (0.8ms) Completed 200 OK in 1789ms (Views: 1707.5ms | ActiveRecord: 1.7ms) Started POST "/admins" for 127.0.0.1 at 2015-04-16 19:37:19 +0530 Processing by AdminsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"5VPDMdM6Cny63T00tcgU55ukkDD9XChTQwWjAJ7IUZ0ELh6D5c7UhbpbOKdQ3atdaNIaBVk5AxctcC0j09pcvQ==", "user"=>{"name"=>"ChiragArya", "email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Create admin account"} User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."is_admin" = ? LIMIT 1 [["is_admin", "t"]] Completed 500 Internal Server Error in 26ms (ActiveRecord: 0.4ms) NameError (uninitialized constant ApplicationController::PermittedParams):
app/controllers/application_controller.rb:26:in permitted_params'
app/controllers/admins_controller.rb:10:in
Rendered /home/chirag/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (54.9ms) Rendered /home/chirag/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (35.3ms) Rendered /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) Rendered /home/chirag/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (227.5ms)

1
Where are your files placed? Share the full route. Also your Permitted_Param.rb should be called Permitted_Params.rbRafa de Castro
@RafadeCastro, since it is Ruby, it should have been calles permitted_params.rb (lower case)Andrey Deineko
@RafadeCastro i instead changed to PermittedParam in controller method and worked perfectly but now after sign-up as admin i am getting another error when i'm signing in. I have cloned this app github.com/mischa78/boxroom NoMethodError in Folders#show <% if permission.group.admins_group? -%>Script-Kiddie
Ok I resolved that one too Damn this code is full of errors :( after accessing admin sign in now error when i am creating new folder :/Script-Kiddie

1 Answers

0
votes

I got the same problem and i resolved that after renaming my strong parameter function name to controllername_params

I don't know where is the mention but i'd love to know that .