Forum: Ruby on Rails How to provide 2 actions to a form?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8c70506408fddb9740b4de7339055c77?d=identicon&s=25 Prashant Tiwari (tiwaripk)
on 2006-03-14 11:30
Hi,
I have a form in rhtml. Now I have 2 buttons indside that form. Clicking
on the first button action will be 'create' & on second button action
will be 'delete'. How to do this?
Thanx
Prash
3319ab6fb19fcf97c8a3d66b8a9b68bf?d=identicon&s=25 Josh on Rails (Guest)
on 2006-03-14 13:21
(Received via mailing list)
On 3/14/06, Prashant Tiwari <tiwari_p_k@yahoo.com> wrote:
>
> I have a form in rhtml. Now I have 2 buttons indside that form. Clicking
> on the first button action will be 'create' & on second button action will
> be 'delete'. How to do this?


Probably the easiest way is to give up on the 'delete' action being a
button, and just making it a link. (You could use images or CSS to style
the
link and the button very similarly.)
9bd3a6bbea1330d30e6a46009bf27097?d=identicon&s=25 Alexandru Copot (copot)
on 2006-03-14 13:58
Don't know much about RoR, but it's pretty simple actually !
<form method="POST" action="">
		<input type="submit" value="Submit" name="B1">
		<input type="submit" value="Submit" name="B2">
</form>

if post->b1 ="submit"
    execute->action1
elseif post->b2 ="submit"
    execute->action2


Josh on Rails wrote:
> On 3/14/06, Prashant Tiwari <tiwari_p_k@yahoo.com> wrote:
>>
>> I have a form in rhtml. Now I have 2 buttons indside that form. Clicking
>> on the first button action will be 'create' & on second button action will
>> be 'delete'. How to do this?
>
>
> Probably the easiest way is to give up on the 'delete' action being a
> button, and just making it a link. (You could use images or CSS to style
> the
> link and the button very similarly.)
9bd3a6bbea1330d30e6a46009bf27097?d=identicon&s=25 Alexandru Copot (copot)
on 2006-03-14 14:20
stupid me
sorry... just tired I guess

<input type="submit" name="submit" value="v1">
<input type="submit" name="submit" value="v2">
<input type="submit" name="submit" value="v3">

if submit = v1
....
.....
...
9bd3a6bbea1330d30e6a46009bf27097?d=identicon&s=25 Alexandru Copot (copot)
on 2006-03-14 14:36
OKAY, just to be a nice guy

template
<%= form_tag(:action => "action2")%>
    <%= submit_tag 'Edit', :name => '_edit_button' %>
    <%= submit_tag 'Delete', :name => '_delete_button' %>
<%= end_form_tag %>


controller
def action2
      render_text params[:_update_button]
end

I hope it's pretty self explainatory !!!


Alex Copot wrote:
> stupid me
> sorry... just tired I guess
>
> <input type="submit" name="submit" value="v1">
> <input type="submit" name="submit" value="v2">
> <input type="submit" name="submit" value="v3">
>
> if submit = v1
> ....
> .....
> ...
9bd3a6bbea1330d30e6a46009bf27097?d=identicon&s=25 Alexandru Copot (copot)
on 2006-03-14 14:39
OKAY - I'm an idiot for today

template
<%= form_tag(:action => "action2")%>
    <%= submit_tag 'Edit', :name => '_button' %>
    <%= submit_tag 'Delete', :name => '_button' %>
<%= end_form_tag %>


controller
def action2
      render_text params[:_button]
end
This topic is locked and can not be replied to.