Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 609201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:32:26+00:00 2026-05-13T17:32:26+00:00

Hey guys I’ve been using the has_and_belongs_to_many relationship with checkboxes example from the Railscast

  • 0

Hey guys I’ve been using the has_and_belongs_to_many relationship with checkboxes example from the Railscast Episode #17 . I had some problems and now everything is working kind of smoothly except the update button will not work.

the edit view looks like so

<% form_for :users, :action => 'update'  do |f| %>
<% for interest in Interest.find(:all) %>
<div>
<%= check_box_tag "user[interest_ids][]", interest.id,
              @user.interests.include?(interest) %>
<%= interest.name %>
</div>
<% end %>
<p>
<%= f.submit 'Update' %>
</p>
<% end %>

and in the controller I have ….

def edit
  @user = User.find(session[:user_id])
end

 def update
  params[:user][:interest_ids] ||= []
  @user = User.find(session[:user_id])
  if @user.update_attributes(params[:user])
  flash[:notice]='User data was updated'
  redirect_to :action => 'index'
 else
  redirect_to :action => 'index'
 end  
end

The button isn’t event doing the redirect… so I dont know whats happening. Is there something in my form creation messing this up? I’m not exactly sure how to create an button and have it access the method in the controller with model updates and etc.

I looked around for help and thought maybe it was because of attr_accessible so I added =>

 attr_accessible :login, :email, :password, :password_confirmation, :interest_ids, :user

to my user model but still nothing…Any I idea why my form isn’t submitting?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:32:26+00:00Added an answer on May 13, 2026 at 5:32 pm

    I played around with the form and the correct code is this ==>

    <% form_for @user do |f| %>
    <% for interest in Interest.find(:all) %>
    <div>
     <%= check_box_tag "user[interest_ids][]", interest.id, @user.interests.include?(interest) %>
     <%= interest.name %>
    </div>
    <% end %>
    <p>
    <%= f.submit 'Edit' %>
    </p>
    <% end %>
    

    I’m so happy! So apparently the problem was :user which should the be object @user.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys I've been having some trouble skipping some unnecessary lines from the txt
hey guys, i was using Json dll in my project from quite sometime now
Hey guys (and gals) I'm having a problem using Assembly GetExportedTypes() in .NET 4.0.
Hey guys am having a bit of problems with my jQuery, I have all
Hey guys i'm making a website but for some reason my div tags are
Hey guys, sorry I'm kind of new to programming, but I had a small
Hey guys I am making a terminal application using Swing and Apache Commons. I
Hey guys I'm creating a quick mysql file to create a DB with some
Hey Guys I've been struggling with this for the last hour and pouring over
Hey guys I just noticed that my join statement here SELECT * FROM reports

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.