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

Want to add individual checkbox fields to Ruby on Rails/Devise form

I'm trying to present users with a series of checkboxes when they register (and also when they press their my account button) that signs them up for certain events.

ex.

First name Last Name Profile name password repeat password

Do you want to attend these events? [ ]Event 1 [X] Event 2 [ ] Event 3

A user isn't required to click on any of them to sign up for an account, but we want to have a simple way for them to be aware of their choices and modify them at any point.

I created a boolean field for each of the events (about two dozen in total), but when I try to sign up, none of the new checkboxes appear. When I try to sign up for a new account, I get this error:

NoMethodError in Registrations#edit Showing /home/ubuntu/workspace/app/views/devise/registrations/edit.html.erb where line #33 raised:

undefined method `nov11underlinecommute' for #<User:0x000000038aa518> Extracted source (around line #33):

<div class="field">
       <h2>Which WHEELS 2015 events are you planning on attending?</h2>
       <h3>Wednesday, November 11th</h3>
     <div><%= f.check_box :nov11underlinecommute, {}, true %> <%= f.label :nov11underlinecommute, "6:30 am -- Underline Commute" %> </div>
     <div><%= f.check_box :fiuride, {}, true %> <%= f.label :fiuride, "5:30 pm -- The 99% Ride from FIU MM Campus to Brickell" %> </div>
   <div><%= f.check_box :brickellbikein, {}, true %> <%= f.label :brickellbikein, "7:00 pm -- Brickell Bike-In Block Party" %> </div>

I already added all of these fields to my db/migrate/add_users file, ran rake db:migrate, and edited my registration controller as well as edit.html.erb to apply all of these fields. I'm not sure how to add it to new registrations (once it works), however.

Github repo: https://github.com/yamilethmedina/wheels_registration.git

Development version (rails server currently running): https://wheels-registration-yamilethmedina.c9.io/

There's probably a better way to do this...if so, can you point me to where I can find out? Thanks!

1 Answer

Hi Yamileth Medina I just cloned the project and run it locally on my machine. everything works well here. I guess you have the issue resolved already?

As for the checkboxes not appearing on the login page, you have to manually include them into the generated devise view files. ("app/views/devise/registration/new"). this is the file that renders the singnup page - edit this.

I hope this is of help to you in some ways.