I use the friendly_id gem. I also have nested routes:
# config/routes.rb map.resources :users do |user| user.resources :events end
So, I have URLs like /users/nfm/events/birthday-2009 .
In my models, I want the event header to be bound to the username, so that both nfm and mrmagoo can have birthday-2009 events without punching them.
# app/models/event.rb def Event < ActiveRecord::Base has_friendly_id :title, :use_slug => true, :scope => :user belongs_to :user ... end
I also use has_friendly_id :username in my user model.
However, in my controller, I only pull out events related to the user who is logged in (current_user):
def EventsController < ApplicationController def show @event = current_user.events.find(params[:id]) end ... end
This does not work; I get an error ActiveRecord::RecordNotFound; expected scope but got none ActiveRecord::RecordNotFound; expected scope but got none .
SO, why should I explicitly specify: scope if I restrict it to current_user.events? And why does current_user.to_param need to be called explicitly? Can I override this?
source share