[英]What is wrong with my routes?
root :to => "index#home"
#public tattoo viewing and submissions
match "/submit" => "index#new", :via => :get
match "/tattoo" => "index#create", :via => :post
match "/tattoo/:id" => "index#show", :via => :get
match "/tagged" => "index#tagged", :via => :get
match "/tattoo/:id" => "index#destroy", :via => :delete
match "/tattoos" => "index#index", :via => :get
members section and its nested images
resources :members, :except => [:new, :create] do
resources :tattoos
end
這就是我的 routes.rb 文件中的內容。 他們生產:
root /(.:format) {:controller=>"index", :action=>"home"}
submit GET /submit(.:format) {:controller=>"index", :action=>"new"}
tattoo POST /tattoo(.:format) {:controller=>"index", :action=>"create"}
GET /tattoo/:id(.:format) {:controller=>"index", :action=>"show"}
tagged GET /tagged(.:format) {:controller=>"index", :action=>"tagged"}
DELETE /tattoo/:id(.:format) {:controller=>"index", :action=>"destroy"}
tattoos GET /tattoos(.:format) {:controller=>"index", :action=>"index"}
members GET /members(.:format) {:action=>"index", :controller=>"members"}
edit_member GET /members/:id/edit(.:format) {:action=>"edit", :controller=>"members"}
member GET /members/:id(.:format) {:action=>"show", :controller=>"members"}
PUT /members/:id(.:format) {:action=>"update", :controller=>"members"}
DELETE /members/:id(.:format) {:action=>"destroy", :controller=>"members"}
但我有一個問題。 出於某種原因,當我嘗試 go 到 mysite.com/submit
我曾經收到此錯誤
No route matches {:controller=>"images"}
上
<%= form_for @tattoo, :html =>{:multipart => true} do |f| %>
但這神奇地變成了:
undefined method `images_path'
在同一條線上。
當我的 controller 有這個時:
indexcontroller def new @tattoo = Image.new end
def create
@tattoo = Image.new(params[:image])
if @tattoo.save
flash[:success] = "Tattoo sent in for approval!"
redirect_to(images_path)
else
render :action => "new"
end
end
然后這個link_to:
<%= link_to "Manage tattoos", member_tattoos_path() %>
給我這個錯誤:
No route matches {:controller=>"tattoos"}
我以為我開始了解路線並且掌握得很好,但我不明白發生了什么!
您需要將成員 object 傳遞給edit_member_path
。
<%= link_to "Edit profile", edit_member_path(@member) %>
edit_member_path
應該知道要編輯的成員的 id。 請試試
<%= link_to "Edit profile", edit_member_path(@member) %>
對於No route matches {:controller=>"images"}
; 由於您的路線中未定義動作圖像,請嘗試停止並重新啟動服務器並檢查是否有任何像回形針這樣的插件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.