0
我有一個名爲「Notes」的控制器,其相關模型是Note,帶有一個名爲「note」(我知道)的文本字段。Rails 2.3.11 RESTful路由不調用從窗體創建動作
我在new.html.erb視圖一個非常簡單的形式:
<% form_for(@note) do |f| %>
<p><%= f.error_messages %> </p>
<h2 class="productList"><label for="">Note: </label>
<%= f.text_area :note, :cols => "50", :rows => "10" %></h2>
<br />
<p><%= f.submit "Create" %></p>
<% end %>
然而,在點擊「提交」按鈕,被調用的行動是從一個完全不同的控制器:
Processing OtherController#add_note (for 127.0.0.1 at 2012-07-30 09:04:42) [POST]
請注意,這個動作甚至沒有在routes.rb中定義,儘管控制器被設置爲資源。
我在routes.rb中「注意事項」路線是這樣的:
map.resources :notes, :collection => { :note_list => :get, :get_json_list => :get }, :member => { :applications => :get, :replace => :get }
和「耙路線」產生這些線控制器:
get_json_list_notes GET /notes/get_json_list(.:format) {:controller=>"notes", :action=>"get_json_list"}
note_list_notes GET /notes/note_list(.:format) {:controller=>"notes", :action=>"note_list"}
notes GET /notes(.:format) {:controller=>"notes", :action=>"index"}
POST /notes(.:format) {:controller=>"notes", :action=>"create"}
new_note GET /notes/new(.:format) {:controller=>"notes", :action=>"new"}
edit_note GET /notes/:id/edit(.:format) {:controller=>"notes", :action=>"edit"}
replace_note GET /notes/:id/replace(.:format) {:controller=>"notes", :action=>"replace"}
applications_note GET /notes/:id/applications(.:format) {:controller=>"notes", :action=>"applications"}
note GET /notes/:id(.:format) {:controller=>"notes", :action=>"show"}
PUT /notes/:id(.:format) {:controller=>"notes", :action=>"update"}
DELETE /notes/:id(.:format) {:controller=>"notes", :action=>"destroy"}
我沒有什麼束縛到我的Javascript中的表單或控件。什麼會使它調用錯誤的控制器和操作?
更新 - 這裏是的form_for標記的輸出:
<form id="new_note" class="new_note" method="post" action="/notes">
<p> </p>
<h2 class="productList">
<label for="">Note: </label>
<textarea id="note_text" rows="10" name="note_text" cols="50"></textarea>
</h2>
<br>
<p>
<input id="note_submit" type="submit" value="Create" name="commit">
</p>
</form>
更新2 - 形式傳遞 「Note.new」
你檢查過form_for helper的輸出嗎? – Bohdan 2012-07-30 13:42:38
我有。這正是你所期望的。在上面發帖。 – AKWF 2012-07-30 14:03:13
從頂部處理路由。你能發佈完整的routes.rb文件嗎? – Bohdan 2012-07-30 14:42:00