title: Rails + simple_form + remote_true + custom controller: how to handle different form actions for 'new' and 'edit'?
body: <p>I'm basically following this tutorial: <a href="http://www.gotealeaf.com/blog/the-detailed-guide-on-how-ajax-works-with-ruby-on-rails" rel="nofollow">http://www.gotealeaf.com/blog/the-detailed-guide-on-how-ajax-works-with-ruby-on-rails</a>
  with a variation: after creating a scaffold for 'tasks' (controller, model, views...) I've created a new controller, named '<strong>demo</strong>', to test the ajax way. So the 'demo' controller has the following actions: index, new_task, create_task, edit_task, update_task. Routes are also adjusted.</p>
  
  <p>When I render the form (app/views/demo/_form.html.erb)</p>
  
  <pre><code>&lt;%= simple_form_for @task, remote: true do |f|   %&gt;
    &lt;%= f.input  :description                      %&gt;
    &lt;%= f.input  :deadline                         %&gt;
    &lt;%= f.button :submit                           %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>the form 'action' will be '/tasks', that corresponds to 'controller:tasks, action:create', but that controller is for "old html" way, while the ajax stuff is in the 'demo' controller. </p>
  
  <p>So, following some answers found on the web I've added the 'url' parameter:</p>
  
  <pre><code>&lt;%= simple_form_for @task, remote: true, url: '/demo/create_task' do |f|   %&gt;
    &lt;%= f.input  :description                      %&gt;
    &lt;%= f.input  :deadline                         %&gt;
    &lt;%= f.button :submit                           %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>In this case it works well for the 'new/create' actions. But when it's time to UPDATE a model it should use '/demo/update_task' path. Which is the Rails way to handle this?</p>
  
  <ol>
  <li><p>Add a line before the form: &lt;% url = @task.new_record? ? "/demo/create_task" : "/demo/update_task?id=#{@task.id}" %></p></li>
  <li><p>Have two different forms, one for creating, other for editing, so 'new_task.js.erb' will point to '_form_for_creating.html.erb' and 'edit_task.js.erb' will point to the other one. Not very DRY actually.</p></li>
  <li><p>Even more ugly:: have 'tasks' controller redirect to 'update_task' in 'demo' controller. I wouldn't rely on this because the tasks controller is supposed to be deleted after some testing.</p></li>
  </ol>