我正在开发一个 ruby on rails 项目,但我遇到了一个非常困难的基本问题。我试图在我的一个控制器中调用自定义操作,但请求以某种方式被重定向到默认的“显示”操作,我不知道为什么。
edit.html.erb 中的链接:
<%= link_to 'Mass Text Entry', :action=>"create_or_add_food_item_from_text" %>
来自 development.log 的错误:
ActiveRecord::RecordNotFound (Couldn't find Menu with ID=create_or_add_food_item_from_text): app/controllers/menus_controller.rb:20:in `show'
routes.rb 文件:
ActionController::Routing::Routes.draw do |map|
map.resources :nutrition_objects
map.resources :preference_objects
map.resources :institutions
map.resources :locations
map.resources :menus
map.resources :food_items
map.resources :napkins
map.resources :users
map.resource :session, :controller => 'session'
map.root :controller=>'pages', :action=>'index'
map.about '/about', :controller=>'pages', :action=>'about'
map.contact '/contact', :controller=>'pages', :action=>'contact'
map.home '/home', :controller=>'pages', :action=>'index'
map.user_home '/user/home', :controller=>'rater', :action=>'index'
map.user_napkins '/user/napkins', :controller=>'rater', :action=>'view_napkins'
map.user_preferences '/user/preferences',:controller=>'rater', :action=>'preferences'
map.blog '/blog', :controller=>'pages', :action=>'blog'
map.signup '/signup', :controller=>'users', :action=>'new'
map.login '/login', :controller=>'session', :action=>'new'
map.logout '/logout', :controller=>'session', :action=>'destroy'
# Install the default routes as the lowest priority.
map.connect ':controller/:action'
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
Menus_controller.rb:
class MenusController < ApplicationController
...
def create_or_add_food_item_from_text
end
...
end
create_or_add_food_item_from_text.html.erb 只是有一个 div 来显示一个带有文本框的表单。我的应用程序的其余部分工作正常,但这让我很难过。
任何帮助表示赞赏。