nums nums - 2 years ago 57
Ruby Question

ActiveRecord::RecordNotFound in AlbumsController#show

In my web app I'm trying to make a show action in which the current_users photos are showed for a particular album when that album is clicked. However, every time I click on the link to the show action I get an error saying 'Couldn't find Album with 'id'=:id [WHERE "albums"."user_id" = ?]'. The show action looks like this:

def show
@album = current_user.albums.find(params[:id])
@photos =


<div class="main">
<div class="main-background">

<% @albums.each do |x| %>
<div class="big-albums"><%= link_to, "/albums/:id", :style => "text-decoration:none;" %></div>
<% end %>

<div class="new-album">
<%= link_to 'New Album', "/albums/new", :style => "text-decoration:none;" %>
<div class="plus-sign">
<%= link_to '+', "/albums/new", :style => "text-decoration:none; color:black; font-size:80px; color:#85adad;" %>



get '/albums' => 'albums#index', as: :albums
get '/albums/new' => 'albums#new'
post '/albums/new' => 'albums#create'
get '/albums/:id' => 'albums#show'
get '/albums/:id/destroy' => 'albums#destroy'

Answer Source

Your issue is the link_to URL you're displaying

link_to, "/albums/:id"

That's assigning :id as the argument passed to the URL. Instead you want to do something like "/albums/#{}" so that it uses the album ID as the ID parameter on the URL path.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download