【发布时间】:2013-11-20 06:06:35
【问题描述】:
当我尝试访问视图时,返回错误:
#Task id: nil, created_at: nil, updated_at: nil 的未定义方法'title'
tasks_controller.rb(控制器)
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(查看)
<%= 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(模型)
class Task < ActiveRecord::Base
belongs_to :user
attr_accessible :title, :details, :user_id, :volunteers
end
我该怎么办?
【问题讨论】:
标签: ruby-on-rails