Note that there are some explanatory texts on larger screens.

plurals
  1. PORouting error. Rendering using get instead of put... Why?
    text
    copied!<p>I have the following code:</p> <p><strong>tasks/_form.html.haml</strong></p> <pre><code>%h3 Tasks %span.form-inline.centered = form_for [@activity, @task], remote: true do |f| = f.text_field :description, {placeholder: 'Enter task description and click + to create a new task', class: 'input-task'} = f.submit "+", class: 'btn btn-danger' </code></pre> <p><strong>controllers/tasks_controller.rb</strong></p> <pre><code> def create activity = Activity.find(params[:activity_id]) flash[:error] = I18n.t "errors.task.generic" if !activity.add_task!(params[:task]) @task = activity.tasks.last respond_to do |format| format.html { redirect_to activity_path(activity) } format.js end end </code></pre> <p><strong>tasks/create.js.erb</strong></p> <pre><code>$('#incomplete-tasks').append("&lt;%= j render partial: 'task', locals: {task: @task} %&gt;"); </code></pre> <p><strong>tasks/_task.html.haml</strong></p> <pre><code>%li = task.description = link_to "Done", activity_task_path(task.activity, task: task), html_options = {method: :put, class: 'pull-right'} </code></pre> <p>The problem that I have is when it tries to use js to render the partial my restful resource <code>activity_task_path</code> sends a get method instead of the put method that I am specifying. If I don't use js to render it and i just refresh the browser it works fine. I now get a routing error because I do no have a show page. I don't however need one. I just need it to update my task via a put method. If anybody can shed some light on why this is happening I would appreciate it.</p> <p><strong>[EDIT1]</strong></p> <p>If you have any questions or need me to add any code or anything else that I can do to help let me know. I really don't understand why this is happening. Thank you.</p> <p><strong>[EDIT2]</strong> </p> <pre><code> def update activity = Activity.find(params[:id]) activity.update_task!(params[:task]) redirect_to activity_path(params[:id]) end </code></pre> <p>This is my update controller.</p> <p><strong>[EDIT3]</strong></p> <p>You can find the app online at <a href="https://trackit.mlpinit.com" rel="nofollow noreferrer">https://trackit.mlpinit.com</a> to get a better understanding of what I am trying to do. You can authenticate with a random email address I have confirmation set to 2.days. </p> <p><strong>[EDIT4]</strong></p> <p>Hopping to make it more clear... Here is the error I get when I add a new task through ajax.</p> <p>Routing Error</p> <p><strong>No route matches</strong></p> <pre><code> {:action=&gt;"show", :controller=&gt;"tasks", :task=&gt;#&lt;Task id: 64, description: "lalala", complete: false, created_at: "2012-10-11 19:41:22", updated_at: "2012-10-11 19:41:22", activity_id: 6&gt;, :activity_id=&gt;#&lt;Activity id: 6, title: "Lala", description: "this is lala", created_at: "2012-10-10 18:37:18", updated_at: "2012-10-10 18:37:18", user_id: 2, activity_group_id: nil&gt;} </code></pre> <p>Once again if I don't do this through an ajax call it works ok. My assumption is that the problem takes place because it doesn't understand the put method for some reason...</p> <p><strong>[EDIT5]</strong></p> <p><strong>If I take of the link from my _task partial the append happens without any errors. I thought I should mention that</strong></p> <p><strong>[EDIT6]</strong></p> <p>I will add a visual walkthrough to make sure that I make myself understood...</p> <p>I have a task form:</p> <p><img src="https://i.stack.imgur.com/k6Myd.png" alt="task form"></p> <p>I enter a task name</p> <p><img src="https://i.stack.imgur.com/u2yAh.png" alt="enter image description here"></p> <p>I hit (enter)plus to create it.</p> <p>I get the following error that is also presented above:</p> <p><img src="https://i.stack.imgur.com/cQLRO.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/nMDBW.png" alt="enter image description here"></p> <p>If I hit refresh the task was generated ok:</p> <p><img src="https://i.stack.imgur.com/s6waq.png" alt="enter image description here"></p> <p>That is why I believe it has to be in the .js.erb file...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload