Is there a way in rails to choose controller action to which form will
be submitted?
Currently I have something like this:
VIEW:
<%= start_form_tag(:action => 'action_chooser', :id => @id %>
....
<%= hidden_field_tag("action_type") %>
<%= link_to_function "action1",
"document.frm.action_type.value='action1'; document.frm.submit()" %> <br>
<%= link_to_function "action2",
"document.frm.action_type.value='action2'; document.frm.submit()" %> <br>
CONTROLLER:
def action_chooser
case action_type
when 'action1'
...
when 'action2'
I would like to have action1 and action2 functions in controller and
somehow choose on the client where to submit.
Thanks,
Igor.
Um, you can have the various actions as functions within the
Controller class. Why would you want to _choose_ actions from a
function within the controller?
···
On 5/10/05, Igor Anic <ianic@4dva.hr> wrote:
Is there a way in rails to choose controller action to which form will
be submitted?
Currently I have something like this:
VIEW:
<%= start_form_tag(:action => 'action_chooser', :id => @id %>
....
<%= hidden_field_tag("action_type") %>
<%= link_to_function "action1",
"document.frm.action_type.value='action1'; document.frm.submit()" %> <br>
<%= link_to_function "action2",
"document.frm.action_type.value='action2'; document.frm.submit()" %> <br>
CONTROLLER:
def action_chooser
case action_type
when 'action1'
...
when 'action2'
I would like to have action1 and action2 functions in controller and
somehow choose on the client where to submit.
Thanks,
Igor.
--
Premshree Pillai
Think about that as a web album.
I display multiple images on a page, with check box below each.
User selects some images and chose action: rotate, flip, delete, ...
So I need to post a form with selected check boxes, but the action depends on the user choice.
Premshree Pillai wrote:
···
Um, you can have the various actions as functions within the
Controller class. Why would you want to _choose_ actions from a
function within the controller?
On 5/10/05, Igor Anic <ianic@4dva.hr> wrote:
Is there a way in rails to choose controller action to which form will
be submitted?
Currently I have something like this:
VIEW:
<%= start_form_tag(:action => 'action_chooser', :id => @id %>
....
<%= hidden_field_tag("action_type") %>
<%= link_to_function "action1",
"document.frm.action_type.value='action1'; document.frm.submit()" %> <br>
<%= link_to_function "action2",
"document.frm.action_type.value='action2'; document.frm.submit()" %> <br>
CONTROLLER:
def action_chooser
case action_type
when 'action1'
...
when 'action2'
I would like to have action1 and action2 functions in controller and
somehow choose on the client where to submit.
Thanks,
Igor.
Sure you can. If you have a field like this:
<inut type="hidden" name="foo" value="bar" />
Then in the controller, you can write:
def action_chooser
case @params['foo']
when 'bar'
...
when 'foobar'
hth,
Douglas
···
On 5/10/05, Igor Anic <ianic@4dva.hr> wrote:
Think about that as a web album.
I display multiple images on a page, with check box below each.
User selects some images and chose action: rotate, flip, delete, ...
So I need to post a form with selected check boxes, but the action
depends on the user choice.
Premshree Pillai wrote:
> Um, you can have the various actions as functions within the
> Controller class. Why would you want to _choose_ actions from a
> function within the controller?
>
> On 5/10/05, Igor Anic <ianic@4dva.hr> wrote:
>
>>Is there a way in rails to choose controller action to which form will
>>be submitted?
>>
>>Currently I have something like this:
>>
>>VIEW:
>><%= start_form_tag(:action => 'action_chooser', :id => @id %>
>>....
>><%= hidden_field_tag("action_type") %>
>><%= link_to_function "action1",
>>"document.frm.action_type.value='action1'; document.frm.submit()" %> <br>
>><%= link_to_function "action2",
>>"document.frm.action_type.value='action2'; document.frm.submit()" %> <br>
>>
>>CONTROLLER:
>>
>>def action_chooser
>> case action_type
>> when 'action1'
>> ...
>> when 'action2'
>>
>>I would like to have action1 and action2 functions in controller and
>>somehow choose on the client where to submit.
>>
>>Thanks,
>>Igor.
>>
>>
>
>
>
Thanks Douglas,
That is exactly the same solution as I'm using now (I describe that in the first post), but I'm looking fore a more elegant solution (without case)
..
Any ideas?
Igor.
Douglas Livingstone wrote:
···
Sure you can. If you have a field like this:
<inut type="hidden" name="foo" value="bar" />
Then in the controller, you can write:
def action_chooser
case @params['foo']
when 'bar'
...
when 'foobar'
hth,
Douglas
On 5/10/05, Igor Anic <ianic@4dva.hr> wrote:
Think about that as a web album.
I display multiple images on a page, with check box below each.
User selects some images and chose action: rotate, flip, delete, ...
So I need to post a form with selected check boxes, but the action
depends on the user choice.
Premshree Pillai wrote:
Um, you can have the various actions as functions within the
Controller class. Why would you want to _choose_ actions from a
function within the controller?
On 5/10/05, Igor Anic <ianic@4dva.hr> wrote:
Is there a way in rails to choose controller action to which form will
be submitted?
Currently I have something like this:
VIEW:
<%= start_form_tag(:action => 'action_chooser', :id => @id %>
....
<%= hidden_field_tag("action_type") %>
<%= link_to_function "action1",
"document.frm.action_type.value='action1'; document.frm.submit()" %> <br>
<%= link_to_function "action2",
"document.frm.action_type.value='action2'; document.frm.submit()" %> <br>
CONTROLLER:
def action_chooser
case action_type
when 'action1'
...
when 'action2'
I would like to have action1 and action2 functions in controller and
somehow choose on the client where to submit.
Thanks,
Igor.