开发者

rails 3 is routing "POST /categories" to the CategoriesController#index action

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?


Found the issue. There was an erroneous line in my routes file that was hijacking the route.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜