1

新しいカテゴリを作成するための 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 の目立たない JavaScript サポートに必要ないくつかのタグを生成します。

<%= csrf_meta_tag %>

何か案は?

4

1 に答える 1

1

問題が見つかりました。ルート ファイルに、ルートを乗っ取っている誤った行がありました。

于 2010-12-17T15:11:32.583 に答える