我有一个用于创建新类别的 ajax 表单。
<%= form_for(@category, :remote => true) do |f| %>
<%= f.error_messages %>
<p>
<%= f.text_field :name %> <%= f.submit 'Add' %>
</p>
<% end %>
在控制器中:
def index
@category = Category.new
...
end
def create
@category = Category.new(params[:category])
...
end
当我提交表单时,我在日志中看到了这个...
Started POST "/categories" for 127.0.0.1 at Tue Dec 14 13:31:46 -0500 2010
Processing by CategoriesController#index as JS
我的路线文件有:
resources :categories
“rake routes”的部分输出:
GET /categories(.:format) {:controller=>"categories", :action=>"index"}
POST /categories(.:format) {:controller=>"categories", :action=>"create"}
而且,我在我的 html HEAD 中包含了这个新的帮助程序,它生成了 rails 3 unobtrusive javascript 支持所需的一些标签:
<%= csrf_meta_tag %>
有任何想法吗?