0
<%= form_for(:offer,:url=>{:controller=>'offers',:action=>'combo'}) do |f|%>

  <%= f.label "Select Category:" %> &nbsp;
  <%= f.select :catId_buy1, options_from_collection_for_select(@categories, "id", "name"), prompt: "Select Category"%>

  <%= f.label "Select Menu:" %> &nbsp;
  <%= f.collection_select :menuName_buy1, Menu.all,:menu_item_name,:menu_item_name, prompt: "Select Menu Item"%>

  <%= f.label "Discountable Quantity:" %> &nbsp;
  <%= f.number_field :qty_buy1%>

  <%= submit_tag("Create New Offer")%>

<%end%>

I am new in rails.I have a dropdown in other page which have values from 1-10.If i select 4 from this dropdown then i want to create controllers like (catId_buy2,menuName_buy2,qty_buy2),(catId_buy3,menuName_buy3,qty_buy3) and so on. Please help me.

Mohammad AbuShady
  • 40,884
  • 11
  • 78
  • 89
John
  • 137
  • 2
  • 12

1 Answers1

0

You can't dynamically create controllers. They are hard coded files that describe the different actions you can do. Rails cannot "guess" what you want to do (except theoretically maybe if you're using standard REST like when you do a scaffold in the console, but even then in practice I believe it's impossible for rails).

I believe what you want to do is instead, pass the category as an argument in your form (that would not be linked to a model, but just used by the controller). Then in your controller, you can do some logic given the value of this attribute. You should have a look at this question.

<%= f.input :menuId, as: :fake %>
Community
  • 1
  • 1
Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164