我有一个newbei Question.i想要向DB插入记录。没有发生错误但记录没有成功保存。我的模型名称是副词,一个字段的名称是name.here是我的代码:
<html>
<body>
<% form_tag new_word_url(@adverb), :method => :post do %>
Name : <%= text_field :adverbs,:name %>
</p>
<p>
<%= submit_tag 'Create' %>
</p>
<% end %>
</body>
</html>
和我的路线
match '/words/new'=>'words#new'
和控制器:
class WordsController < ApplicationController
def new
@adverb=Adverb.new
end
def create
@adverb=Adverb.create(params[:adverb])
if @adverb
redirect_to :action => 'index'
else
render :action => 'new'
end
end
def index
@adverb =Adverb.find(:all)
end
def edit
@adverb =Adverb.find(params[:id])
end
end
谢谢你的帮助
答案 0 :(得分:0)
Name : <%= text_field :adverbs,:name %>
应该是
Name : <%= text_field :adverb,:name %>
和
<% form_tag new_word_url(@adverb), :method => :post do %>
应该是
<% form_tag adverbs_path, :method => :post do %>
并在您的路线中
resources :adverbs