所以我有一个非常简单的布局。我的配置路线是:Rails路径给我没有路径匹配,但我不明白为什么
resources :webcomics
match '/webcomics/first' => 'webcomics#first', :as => :first
match '/webcomics/random' => 'webcomics#random', :as => :random
match '/webcomics/latest' => 'webcomics#latest', :as => :latest
控制器:
def show
@webcomic = Webcomic.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @webcomic }
end
end
def first
@webcomic = Webcomic.order("created_at ASC").first
respond_to do |format|
format.html { render 'show'}
format.json { render json: @webcomic }
end
end
导航栏:
<%= link_to first_webcomics_path, :rel => "tooltip", :title => "first comic" do %>
formatting in here
<% end %>
当我点击这个链接,它把我送到了正确的道路/ webcomics /第一,但它给了我错误
Routing Error
No route matches {:action=>"edit", :controller=>"webcomics"}
我打破了我的脑袋它怎么会'编辑',并且不管这个消息是完全错误的,我确实有编辑,但为什么它会尝试去编辑动作。耙路由
def edit
@webcomic = Webcomic.find(params[:id])
end
结果:
first_webcomics GET /webcomics/first(.:format) webcomics#first
latest_webcomics GET /webcomics/latest(.:format) webcomics#latest
random_webcomics GET /webcomics/random(.:format) webcomics#random
webcomics GET /webcomics(.:format) webcomics#index
POST /webcomics(.:format) webcomics#create
new_webcomic GET /webcomics/new(.:format) webcomics#new
edit_webcomic GET /webcomics/:id/edit(.:format) webcomics#edit
webcomic GET /webcomics/:id(.:format) webcomics#show
PUT /webcomics/:id(.:format) webcomics#update
DELETE /webcomics/:id(.:format) webcomics#destroy
root / webcomics#index
我这样做太 - 仍然得到同样的错误。如果问题出在订单上,我也不会得到不同的错误吗? – StanM 2013-04-10 01:24:43
@StanM No;用'match'它试图将RESTful动作名称解释为ID。为什么它说没有编辑方法我不确定,因为你说有一个。请将'rake routes'运行结果添加到您的问题中。 – 2013-04-10 01:28:16
已被添加到原始帖子 – StanM 2013-04-10 01:30:59