Hey, I have a controller messages which for the index action lists messages. I want buttons to be able to serve actions "mark_read" and "delete". how do i create my form to be able to submit the buttons without it redirecting to the create action for my controller ? chubbs --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
hey i asked this a while back and am still struggling to work out a nice way to do this, can anyone help? On Jan 14, 11:13 pm, Chubbs <acetin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey, > > I have a controller messages which for the index action lists > messages. I want buttons to be able to serve actions "mark_read" and > "delete". > > how do i create my form to be able to submit the buttons without it > redirecting to the create action for my controller ? > > chubbs--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 14/01/2008, Chubbs <acetinick-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey, > > I have a controller messages which for the index action lists > messages. I want buttons to be able to serve actions "mark_read" and > "delete". > > how do i create my form to be able to submit the buttons without it > redirecting to the create action for my controller ? > > chubbsIf I understood you correctly, "by clicking mark read", it should update a mark_read boolean field to be true instead of false, in that case you can set your form to go to PUT process (update action method), and for delete you can still go to DELETE process (destroy action method) in your controller. But my solution here is involving two forms for each of your record inside your object listing iteration. cos I don''t see the reason why combine them in one. ex. form_tag book_path(book), :method => :put do hidden_field_tag :mark_read, :value => "1" end and form_tag book_path(book), :method => :delete do hidden_field_tag :id, :value => book.id end -- r9 = { name: Rie!, ym: riyari3, skype: rubyninja, li: http://linkedin.com/in/ariekeren, fb: http://profile.to/ariekeren, blog: http://tinyurl.com/2bjgvn } --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ye i kinda need it to be in one form cos i have check boxes for each
of the messages
i made it work like this:
<% form_tag :action => "inbox_action" do %>
.....
<%= check_box_tag("select[]", message.id, false) %>
<%= submit_tag("Delete", :name => "submit" )%>
<%= submit_tag("Mark Read", :name => "submit")%>
<% end %>
def inbox_action
case params[:submit]
when ''Delete''
destroy #destroy action
when ''Mark Read''
if(params[:select])
selected_pms = @current_user.user_privmsgs.find(params[:select])
for pm in selected_pms
pm.is_unread = false
pm.save
end
end
end
redirect_to privmsgs_url
end
bit confused how this works with using rest, so i dont it that way.
dunno if its a good way to do it tho.
chubbs
On Jan 26, 7:58 pm, Rie!
<ariekusumaatma...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> On 14/01/2008, Chubbs
<acetin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > Hey,
>
> > I have a controller messages which for the index action lists
> > messages. I want buttons to be able to serve actions
"mark_read" and
> > "delete".
>
> > how do i create my form to be able to submit the buttons without it
> > redirecting to the create action for my controller ?
>
> > chubbs
>
> If I understood you correctly, "by clicking mark read", it should
> update a mark_read boolean field to be true instead of false, in that
> case you can set your form to go to PUT process (update action
> method), and for delete you can still go to DELETE process (destroy
> action method) in your controller. But my solution here is involving
> two forms for each of your record inside your object listing
> iteration. cos I don''t see the reason why combine them in one.
>
> ex.
> form_tag book_path(book), :method => :put do
> hidden_field_tag :mark_read, :value => "1"
> end
>
> and
> form_tag book_path(book), :method => :delete do
> hidden_field_tag :id, :value => book.id
> end
>
> --
> r9 = { name: Rie!, ym: riyari3, skype: rubyninja,
> li:http://linkedin.com/in/ariekeren,
> fb:http://profile.to/ariekeren,
> blog:http://tinyurl.com/2bjgvn}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---