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?