I’m making a message board application. Users can make a post, each post requires a tag. Users can comment on the posts. Pretty simple. I’ve been hacking away on it and got an error I can’t explain. I made a post, message#index shows the the list of posts including the newest one. The title of each post links to the message#show view (nothing special here) and the 24 other posts on message#index can be clicked on to visit their associated message#show. But not this recent one. I get the following error when I visit the message#show of the offending post:
Couldn't find Tag with ID=131
...
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1586:in `find_one'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1569:in `find_from_ids'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:616:in `find'
/home/vvlist/website/app/controllers/messages_controller.rb:20:in `show'
messages_controller.rb:20:
@tag = Tag.find(params[:id])
I really don’t understand what’s going on here. Can someone enlighten me? I’ll post any other needed code. Thank you for reading my question.
The problem is that you’re looking up the tag using the message id. In the
messages#showactionparams[:id]is the the id of theMessagemodel, not the tag.Assuming that
Tagis an association ofMessagesuch ashas_one :tagorhas_many :tagsthen you can get a message tag as using:or