Rails 3 正在路由“POST /categories”到 CategoryController#index 操作
我有一个用于创建新类别的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 路线”的部分输出:
GET /categories(.:format) {:controller=>"categories", :action=>"index"}
POST /categories(.:format) {:controller=>"categories", :action=>"create"}
并且,我在我的 html HEAD 中包含了这个新的帮助程序,它生成一些标签需要 Rails 3 不显眼的 javascript 支持:
<%= csrf_meta_tag %>
有什么想法吗?
I have an ajax form for creating a new Category.
<%= form_for(@category, :remote => true) do |f| %>
<%= f.error_messages %>
<p>
<%= f.text_field :name %> <%= f.submit 'Add' %>
</p>
<% end %>
In the controller:
def index
@category = Category.new
...
end
def create
@category = Category.new(params[:category])
...
end
When I submit the form, I see this in my log...
Started POST "/categories" for 127.0.0.1 at Tue Dec 14 13:31:46 -0500 2010
Processing by CategoriesController#index as JS
My routes file has:
resources :categories
Partial output of "rake routes":
GET /categories(.:format) {:controller=>"categories", :action=>"index"}
POST /categories(.:format) {:controller=>"categories", :action=>"create"}
And, I'm including this new helper in my html HEAD that generates some tags that are needed for rails 3 unobtrusive javascript support:
<%= csrf_meta_tag %>
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发现问题了。我的路线文件中有一个错误的行正在劫持路线。
Found the issue. There was an erroneous line in my routes file that was hijacking the route.