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!

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

TreeBook database is not storing first_name or last_name

It looks like my TreeBook app is functioning correctly for the most part; however, whenever I signup a user, the entries for first_name and last_name do not get saved. So, whenever I try to view a status from that user, an error comes up because the app cannot find a name to display in the database. Anyone have any thoughts?

For reference, I'm up to Build a Simple Ruby on Rails Application > Customizing Forms > Creating Relationships

Just so it's available to other users that will come across this if they are using Rails 4.0.0rc2+

I had the same issue and after reading up on devise documentation I found to solve your issue you can place the following in your Application Controller, it tells the devise controller to accept these parameters as permitted parameters:

before_filter :configure_permitted_parameters, if: :devise_controller?

protected

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

I'm not sure if this is secure, so if someone more experienced with Ruby/RoR sees an issue by all means let me know, but this was based off the documentation for devise, found here

Marek Dano
Marek Dano
6,419 Points

Thanks, it works for me. I'm using Rails 4 with Ruby 2.0. I'm also not not sure if this approach is secure.

1 Answer

Did you migrate the database? rake db:migrate with the migration that adds those columns to the database?

Yes - I tried migrating the database again, but no luck.

Then you need to show us code.

go to gist.github.com and post the following files:

Your database Migration that was generated. located in db/migrate/ The statuses controller The status model and your _form.html.erb and new.html.erb views

Note you can post multiple files in one gist on that site, dont make more than one gist.

Here is the gist with my code: https://gist.github.com/davesolow/6215467

Thank you for the help!

What version of rails are you using? type: rails -v in console and tell me what you're using.

4.0.0.rc2

You need to use Rails 3.2.14. There is a VERY large difference between 3.2.x and 4.x. The videos were made using 3.2.x. I'd suggest downloading the project files or restarting the project from scratch making sure that rails version in your gemfile is set to 3.2.14.

Got it - I'm working off the project files now and everything is going much smoother. Thanks for the help Richard!