I have been working on my first project in rails and have stumbled across a problem while using tags. I have it working so when the user clicks a tag it shows all entries associated with that tag. However when I try to make those names link to the show page for that entry I receive this error:
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">}
I have been trying to fix it for hours but have had no luck. If anyone has some advice to solve this problem it would be much appreciated.
Controller:
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
Routes:
Animedb::Application.routes.draw do
resources :animes do
resources :characters
end
match 'tagged' => 'characters#tagged', :as => 'tagged'
View:
<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>