Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: How to make a form post to another controller action

I know you are usually supposed to use the linking between new/create and edit/update in rails, but I have a case where I need something else. Is there anyway I can achieve this same connection?

I have a form for a model and I want it to post the data (similar to how a new view, post to the create action).

Here is my form

<div id="new-job">  
  <%= form_for(@job) do |f| %>
    <% if @job.errors.any? %>
      <div id="error_explanation">
        <h2><%= pluralize(@job.errors.count, "error") %> prohibited this job from being saved:</h2>

        <ul>
        <% @job.errors.full_messages.each do |msg| %>
          <li><%= msg %></li>
        <% end %>
        </ul>
      </div>
    <% end %>

    <div class="field">
      <%= f.label :name %><br />
      <%= f.text_field :name %>
    </div>
    <div class="field">
      <%= f.label :location %><br />
      <%= f.text_field :location %>
    </div>
    <div class="field">
      <%= f.label :description %><br />
      <%= f.text_area :description %>
    </div>
    <div class="actions">
      <%= f.submit "create job", id: "submit-job", class: "button small radius" %>
      <%= link_to "go back", jobs_path, class: "button small radius secondary" %>
      <div id="new-job-errors"> </div>
    </div>
  <% end %>
</div>
like image 730
user2158382 Avatar asked Jun 09 '13 00:06

user2158382


1 Answers

Use the :url option.

= form_for @job, :url => company_path, :html => { :method => :post/:put }
like image 81
OneChillDude Avatar answered Oct 18 '22 21:10

OneChillDude