我正在学习 HAML,但我对 from_for 有疑问
%b New Advert!
- form_for @car, :url => { :action => "create" } do |f|
= f.text_field :body
= f.submit t('advert.form.save')
我的控制器
class AdvertController < ApplicationController
def new
@car = Car.new
end
def create
@car = Car.new(params[:car])
end
end
还有我的模型 car.rb
class Car < ActiveRecord::Base
attr_accessible :title, :body
end
但我有一个错误:
# 未定义的方法“body”
广告中的 NoMethodError#new
显示 /my_project/app/views/advert/new.html.haml 其中第 4 行提出
带有“=”的UPD form_for 不起作用
= form_for @car, :url => { :action => "create" } do |f|
= f.text_field :body
= f.submit t('advert.form.save')