When I try to access the view, an error is returned:
undefined method 'title' for #Task id: nil, created_at: nil, updated_at: nil
tasks_controller.rb (Controller)
class TasksController < ApplicationController
def new
@task = Task.new
end
def create
@task = Task.new(params[:task])
if @task.save
redirect_to new_task_path
end
end
end
/tasks/new.html.erb (View)
<%= form_for :task, url: tasks_path do |f| %>
<p>
<%= f.label :title %><br>
<%= f.text_field :title %>
</p>
<p>
<%= f.label :details %><br>
<%= f.text_area :details %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
task.rb (Model)
class Task < ActiveRecord::Base
belongs_to :user
attr_accessible :title, :details, :user_id, :volunteers
end
What should I do?