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.
Prashant T. (Guest)
on 2006-03-14 12: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
Josh on Rails (Guest)
on 2006-03-14 14:21
(Received via mailing list)
On 3/14/06, Prashant T. <removed_email_address@domain.invalid> 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.)
Alexandru C. (Guest)
on 2006-03-14 14: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 T. <removed_email_address@domain.invalid> 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.)
Alexandru C. (Guest)
on 2006-03-14 15: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
....
.....
...
Alexandru C. (Guest)
on 2006-03-14 15: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
> ....
> .....
> ...
Alexandru C. (Guest)
on 2006-03-14 15: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.