所以我有一个我认为非常简单的布局。我的配置路线是:
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/first,但它给了我错误
Routing Error
No route matches {:action=>"edit", :controller=>"webcomics"}
我正在打破我的头,它是如何“编辑”的,不管这条消息是完全错误的,我确实有编辑,但为什么它会尝试进行操作编辑。
def edit
@webcomic = Webcomic.find(params[:id])
end
rake 路由的结果:
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