Trouble figuring out Edit
|
|
I’ve gotten upto the enhancing monkeytasks with the edit function, this is where I’m stuck. I’ve managed to make an edit.html.erb page within the today view and it contains: <% form_for :task, :url => {:controller => :task, :action => :update}, :html => {:id => ‘addtaskform’} do |t| %> <label for="task_name">Task:</label> <%= t.text_field ‘name’ %> <label for="task_due_date">Due Date:</label> <%= t.text_field ‘due_date’ %> <%= submit_tag “Update Task” %> <% end %> And this in the todo partial to link to the edit: In my task_controller I have this for edit: def edit
@task = current_user.tasks.find(params[:id]) And for update: def update
@task.attributes = params[:id]
@task.save!
redirect_to(:controller => “main”) Clicking edit on an item loads the edit page with the correct information for that item entered, however clicking update causes this error: active_record/base.rb:1251:in `find_from_ids’ Couldn’t find Task without an ID Line 57 of the task controller is: def find_task
@task = current_user.tasks.find(params[:id]) Any help to point me in the right direction would be great! Thanks. |
|
|
You might try something along these lines (obviously missing a whole lot of formatting)
<h1>Editing Task</h1>
<%= error_messages_for :task %>
<% form_for(@task) do |f| %>
<%= f.text_field :name %>
<%= f.text_field : due_date %>
<%= f.submit "Update Task" %>
<% end %>
|