# Restful multi button form

**URL:** <https://www.ruby-forum.com/t/restful-multi-button-form/125983>\
**Category:** Rails\
**Created:** [January 14, 2008, 1:14pm UTC](https://www.ruby-forum.com/t/restful-multi-button-form/125983 "2008-01-14T13:14:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chubbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chubbs](https://www.ruby-forum.com/u/Chubbs)\
**Post date:** [January 14, 2008, 1:14pm UTC](https://www.ruby-forum.com/t/restful-multi-button-form/125983/1 "2008-01-14T13:14:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chubbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chubbs](https://www.ruby-forum.com/u/Chubbs)\
**Post date:** [January 26, 2008, 9:33am UTC](https://www.ruby-forum.com/t/restful-multi-button-form/125983/2 "2008-01-26T09:33:44Z")

</div>

hey i asked this a while back and am still struggling to work out a  
nice way to do this,

can anyone help?

---

<div class="post-metadata">

**Author:** ![Chubbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chubbs](https://www.ruby-forum.com/u/Chubbs)\
**Post date:** [January 26, 2008, 9:59am UTC](https://www.ruby-forum.com/t/restful-multi-button-form/125983/3 "2008-01-26T09:59:48Z")

</div>

On 14/01/2008, Chubbs [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](http://linkedin.com/in/ariekeren),  
fb: [Buy Real Facebook Likes | Pay for FB Likes - Profile.to](http://profile.to/ariekeren),  
blog: [http://tinyurl.com/2bjgvn](http://tinyurl.com/2bjgvn) }

---

<div class="post-metadata">

**Author:** ![Chubbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chubbs](https://www.ruby-forum.com/u/Chubbs)\
**Post date:** [January 26, 2008, 10:10am UTC](https://www.ruby-forum.com/t/restful-multi-button-form/125983/4 "2008-01-26T10:10:58Z")

</div>

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
