Trouble figuring out Edit

Subscribe to Trouble figuring out Edit 2 post(s), 2 voice(s)

 
Avatar SashaSki 4 post(s)

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:
<%= link_to ‘Edit’, :controller => ‘main’, :action => ‘edit’, :id => todo.id %>

In my task_controller I have this for edit:

def edit @task = current_user.tasks.find(params[:id])
end

And for update:

def update @task.attributes = params[:id] @task.save! redirect_to(:controller => “main”)
end

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’
active_record/base.rb:503:in `find’
active_record/associations/has_many_association.rb:66:in `find’
app/controllers/task_controller.rb:57

Couldn’t find Task without an ID

Line 57 of the task controller is:

def find_task @task = current_user.tasks.find(params[:id])
end

Any help to point me in the right direction would be great! Thanks.

 
Avatar EldonAlameda Administrator 216 post(s)

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 %>