0
我一直在使用rails的第一個項目,並在使用標籤時偶然發現了一個問題。我有它的工作,所以當用戶點擊標籤時,它會顯示與該標籤相關的所有條目。然而,當我試圖讓那些名字鏈接到顯示頁面該條我收到此錯誤:Ruby on Rails:鏈接到資源顯示頁面結果No Route Matches
No route matches {:action=>"show", :controller=>"characters", :anime_id=>#<Character id: 1, name: "Kamina", description: "Badass", occupation: "Team Dai-Gurren", anime_id: 1, created_at: "2013-06-06 01:00:57", updated_at: "2013-06-06 03:28:20">}
我一直在試圖修復它幾個小時,但有沒有運氣。如果有人有一些建議來解決這個問題,將不勝感激。
控制器:
class CharactersController < ApplicationController
def create
@anime = Anime.find(params[:anime_id])
@character = @anime.characters.create(params[:character])
redirect_to anime_path(@anime)
end
def show
@anime = Anime.find(params[:anime_id])
@character= @anime.characters.find(params[:id])
end
def index
@anime = Anime.find(params[:anime_id])
@characters= @anime.characters.all
end
def tagged
@anime = Anime.find(params[:anime_id])
if params[:tag].present?
@characters = @anime.characters.tagged_with(params[:tag])
else
@characters = @anime.characters.postall
end
end
end
路線:
Animedb::Application.routes.draw do
resources :animes do
resources :characters
end
match 'tagged' => 'characters#tagged', :as => 'tagged'
查看:
<h1>Listing Characters</h1>
<table>
<tr>
<th>Name</th>
<th>Year</th>
<th>Season</th>
<th>Genre</th>
<th></th>
<th></th>
<th></th>
<% @characters.each do |character| %>
<tr>
<td><%= link_to character.name, anime_character_path(character) %></td>
</tr>
<% end %>
</table>
Ahhhh。謝啦! –
@MontyMonro很高興能幫到你! :) –