Hey,
I''m adding objects to an array, where they are displayed elsewhere on
the page.
I went to add the remove method, called by the remove button on the
page, and it''s not functioning as I would hope. I figured this is a
straightforward thing, but I want to do it the right way.
Add in view
<%= link_to_remote ''Add'',
:url => { :action => ''add_subject'', :id =>
subject },
:update => ''added_subjects''%>
Add in controller
def add_subject
@added_subjects = find_added_subjects
@added_subjects << Subject.find(params[:id])
render :partial => ''added_subjects'', :layout =>
false
end
I tried this for the remove,
View
<%= link_to_remote ''Remove'',
:url => { :action => ''remove_subject'', :id =>
subject },
:update => ''added_subjects'' %>
Controller
def remove_subject
@added_subjects = find_added_subjects
@added_subjects.reject! { |subject| subject.id == params[:id] }
render :partial => ''added_subjects'', :layout =>
false
end
Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---