rails update redirecting to wrong controller
I have a model for a task which has a name, description, the process it belongs to, the position and a category.
As there are only two different categories I have created additional controllers specific to the categories as they need to be treated differently. when i submit the edit form in one of the category controllers it i开发者_运维知识库s redirecting back to the main tasks controllers show action. It seems to be skip the category controller all together (I tested this by just rendering text at each stage, it doesn't even touch the update action). I looked at the html output that is rendered and the form is being submitted to the wrong controller, but I can't see any way to change that.
So how do you set the form action in rails?
sub category controller edit:
def edit
@task = Task.find(params[:id])
@procedures = Procedure.find(:all, :conditions => "comdecom = true")
@gettasks = Task.all
end
This renders the category view edit:
<div id="page">
<h1>Editing Commissioning task</h1>
<%= render :partial => 'form' %>
<%= link_to 'Back', com_tasks_path %>
</div>
With the partial 'form':
<div id="form">
<% form_for(@task) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :description %><br />
<%= f.text_area :description %>
</p>
<p> To format your text you can use either html or the redcloth textile markup language. A full list of commands can be found at <a href="http://redcloth.org/"> http://redcloth.org/ </a></p>
<p>
<%= swapselect :task, @task, :procedure, @procedures.map {|procedure|[procedure.name, procedure.id]} %>
</p>
<p>
<%= f.label :position, 'Position after:' %><br />
<%= f.collection_select "position", @gettasks, :position, :name %>
</p>
<p>
<%= f.hidden_field :comdecom, :value => '1' %>
<%= f.hidden_field :active, :value => '1' %>
</p>
<p>
<%= f.submit 'Submit' %>
</p>
<% end %>
</div>
When you hit the submit button it takes you through to the tasks controller.
I found that you can put a URL to the form for it to go to after so I have changed the form opening tags to:
<% form_for(@task, :url => {:controller => 'com_tasks', :action => 'update', :id => params[:id]}) do |f| %>
I had to get rid of my partials because I couldn't specify both actions.
精彩评论