Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Ruby in Rails Error. Help!

I was following along with the first Ruby on Rails course and on Generating the User Model the attr_accessible wasn't there so I added them in and then when I went to run the rails server I got this error: Exiting /home/charliethomas/Projects/treebook/config/initializers/devise.rb:7:in block in <top (required)>': undefined methodsecret_key=' for Devise:Module (NoMethodError) from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.0.0.rc/lib/devise.rb:265:in setup' from /home/charliethomas/Projects/treebook/config/initializers/devise.rb:3:in<top (required)>' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:223:in load' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:223:inblock in load' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:214:in load_dependency' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:223:inload' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/engine.rb:609:in block (2 levels) in <class:Engine>' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/engine.rb:608:ineach' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/engine.rb:608:in block in <class:Engine>' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/initializable.rb:30:ininstance_exec' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/initializable.rb:30:in run' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/initializable.rb:55:inblock in run_initializers' from /home/charliethomas/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:150:in block in tsort_each' from /home/charliethomas/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:183:inblock (2 levels) in each_strongly_connected_component' from /home/charliethomas/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:210:in block (2 levels) in each_strongly_connected_component_from' from /home/charliethomas/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:219:ineach_strongly_connected_component_from' from /home/charliethomas/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:209:in block in each_strongly_connected_component_from' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/initializable.rb:44:ineach' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/initializable.rb:44:in tsort_each_child' from /home/charliethomas/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:203:ineach_strongly_connected_component_from' from /home/charliethomas/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:182:in block in each_strongly_connected_component' from /home/charliethomas/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:ineach' from /home/charliethomas/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in each_strongly_connected_component' from /home/charliethomas/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:148:intsort_each' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/initializable.rb:54:in run_initializers' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/application.rb:215:ininitialize!' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/railtie/configurable.rb:30:in method_missing' from /home/charliethomas/Projects/treebook/config/environment.rb:5:in<top (required)>' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in require' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:inblock in require' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:214:in load_dependency' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:inrequire' from /home/charliethomas/Projects/treebook/config.ru:3:in block in <main>' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:55:ininstance_eval' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:55:in initialize' from /home/charliethomas/Projects/treebook/config.ru:innew' from /home/charliethomas/Projects/treebook/config.ru:in <main>' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:49:ineval' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:49:in new_from_string' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:40:inparse_file' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/server.rb:277:in build_app_and_options_from_config' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/server.rb:199:inapp' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/commands/server.rb:48:in app' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/server.rb:314:inwrapped_app' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/commands/server.rb:75:in start' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/commands.rb:76:inblock in <top (required)>' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/commands.rb:71:in tap' from /home/charliethomas/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/commands.rb:71:in<top (required)>' from bin/rails:4:in require' from bin/rails:4:in<main>'

2 Answers

The attr_accessible method has been depreciated in the latest version of Rails. So if you're running version 4 of Rails, this is probably the problem.

So should I put nothing or is there an alternative syntax

From what I've read, others have just left it out.

Thanks

For Rails 4 and Devise:

It's tricky for me as I'm a noob. It's a two part solution for the controller page: Works for me, FYI, I use a :profile_name here and you may not

class ApplicationController < ActionController::Base
    # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  before_filter :configure_permitted_parameters, if: :devise_controller?


protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) { |u| u.permit( :first_name, :last_name, :profile_name, :password_confirmation, :password, :email ) }
    devise_parameter_sanitizer.for(:sign_in) { |u| u.permit( :profile_name, :password, :email ) }
  end

end

nice!