1
我有一个用于创建新类别的ajax表单。rails 3将“POST/categories”路由到CategoriesController#index操作
<%= 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
“耙路”部分输出:
GET /categories(.:format) {:controller=>"categories", :action=>"index"}
POST /categories(.:format) {:controller=>"categories", :action=>"create"}
而且,我包括我的HTML HEAD这个新的辅助,其生成所需的轨道3不显眼的JavaScript支持一些标签:
<%= csrf_meta_tag %>
任何想法?