views:

82

answers:

2

I have 3 different actions in a controller. Each takes different number of parameters. In the application, all 3 are executed by the user clicking through links. Now I need to have a form with a couple of fields where users can simply type what they are looking for. When users fill out the form, depending on what is provided one of the 3 actions has to be executed.

So in short I need to take strings from the form, identify which action is needed, and pass the strings into one of the 3 actions as parameters.

Sorry I am a newbie in Rails, and if you don't understand my question I will provide clarification :)

Thanks always.

[edit]

All 3 actions act pretty much the same, except the parameters. So in the index page, i have the following 3 links to the 3 actions.

<h3>
<%= link_to "1. NPA", :controller => "trunks", :action => "npa" %> <br />
<%= link_to "2. Switch", :controller => "trunks", :action => "switches" %><br />
<%= link_to "3. Trunk Group CLLI", :controller => "trunks", :action => "clli" %>

Say you click on the first link which invokes 'npa' action, you will be presented with a list of links again generated by the following code:

<h3>
<% while j < @npa.size %>
  <% if @npa[j] != nil%>
    <%= link_to "#{@npa[j]}", :controller => "trunks", :action => "npanxx", :param1 => "#{@npa[j]}", :param2 => "#{@npa[j]}"%><br />
  <% end %>
  <% j += 1 %>
<% end %>
</h3>

In the above code, there are 2 parameters (param1 and param2) being passed on to the next action 'npanxx'.

What I need to achieve is the same as above, but by getting the parameters from form fields.

Depending on which parameters are provided by the user, I guess I can make the application decide which action has to be executed. For example, parameters for the above actions are all numerical, but for the second action the parameters are all string.

So it just comes down to how to take the input from the user, and pass them on to an action in a controller.

Thanks for help everyone :)

A: 

You could submit the form to a controller action that does the 'identity which action is needed', which then redirects to the action specific to the parameters passed.

I think a more advanced approach would be add the 'identify action' logic in your routing configuration.

Dylan McClung
ok i guess my problem is "how to submit the form to a controller". Sorry I am a newbie xD
mr.flow3r
A: 

In regards to your question to Dylan McClung about how to submit the form to a controller, a simple submit_to_remote (if you wanted AJAX response) or submit_tag (if you wanted standard HTTP response)

Submit To Remote

Submit Tag

Eric