I have a newbei Question.i want to insert a record to DB. no error occured but record has been not saved successfuly .my model name is adverb and the name of one field is name.here is my code:
<html>
<body&开发者_StackOverflow中文版gt;
<% form_tag new_word_url(@adverb), :method => :post do %>
Name : <%= text_field :adverbs,:name %>
</p>
<p>
<%= submit_tag 'Create' %>
</p>
<% end %>
</body>
</html>
and in my route
match '/words/new'=>'words#new'
and Controller:
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
thank you for your helps
Name : <%= text_field :adverbs,:name %>
should be
Name : <%= text_field :adverb,:name %>
AND
<% form_tag new_word_url(@adverb), :method => :post do %>
should be
<% form_tag adverbs_path, :method => :post do %>
and in your routes
resources :adverbs
精彩评论