Darren,

If you look at the log here, you'll see the problem.

Started GET "/entries/showphotos" for 127.0.0.1 at Fri Aug 13 23:37:45
> +0100 2010
>   Processing by EntriesController#show as JS
>   Parameters: {"id"=>"showphotos"}
>   Entry Load (0.2ms)  SELECT `entries`.* FROM `entries` WHERE
> (`entries`.`id` = 0) LIMIT 1
> Completed   in 8ms

As you're using restful routes, you get a number of routes for free by
putting in resources :entries. When you supply your url by putting in
the action and controller, it comes across and rails things you're
trying to hit the show action because you're supplying the first part
"/entries" followed by a second item that it doesn't know, so it hits
the "show" action. That's why you see the line where it tries to pull
up an entry with id of 0 ("showphotos.to_i" == 0).

To solve your problem, put a named route ABOVE the resource :entries
line. As previously suggested, you could add this line.

match '/entries/showphotos', :to => 'entries#showphotos', :as =>
'showphotos'

However, you won't know what entry you'll be adding photos to so be
sure to add an ID as well.

match '/entries/showphotos/:id', :to => 'entries#showphotos', :as =>
'showphotos'

Just remember, you'll need to put the more specific routes higher as
they get higher priority.

- Robert


On Aug 13, 6:39 pm, "Ruby on Rails: Talk" <[email protected]>
wrote:
> Oh ... And if I change it to ... <%= link_to "Add Photos", '/entries/
> showphotos', :remote => true %>
>
> I get ...
>
> Started GET "/entries/showphotos" for 127.0.0.1 at Fri Aug 13 23:37:45
> +0100 2010
>   Processing by EntriesController#show as JS
>   Parameters: {"id"=>"showphotos"}
>   Entry Load (0.2ms)  SELECT `entries`.* FROM `entries` WHERE
> (`entries`.`id` = 0) LIMIT 1
> Completed   in 8ms
>
> ActiveRecord::RecordNotFound (Couldn't find Entry with ID=showphotos):
>   app/controllers/entries_controller.rb:4:in `show'
>
> Hence why I'm slowly going insane ...
>
> Maddeningly Darren

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to