load_resource by params other then object_id #132

Closed
avstudio opened this Issue Aug 26, 2010 · 3 comments

3 participants

@avstudio

HI

is it possible to load resource passing params name like username?
in my project i'm using path_prefix and pass username as id. CanCan can't find resource
and raise exception.

  • if cannot, will be this on TODO in the future, and how can i override for now some method and pass something different than object_id to skip custom fetching instance ?

I'm new one in ruby and love cancan.
Sorry for english
Thanks

----update---

i found temp solution for this issues overriding this methods for find resource:

OLD

  def id_param
      @params[parent? ? :"#{name}_id" : :id]
    end

overrided

 

  def id_param
   @params[parent? ? :"#{name}_id" : @options[:find_by] ? @options[:find_by].to_sym : :id]

  end

maybe something will be included into next release
Thanks anyway

@ryanb
Owner

Just so I understand correctly, do you want to use a different parameter than params[:id] to find the record by? Is there a reason you aren't passing the name as the :id parameter in the routes?

@ryanb
Owner

Closing since there hasn't been any response. If this is still a problem, comment here and I'll re-open.

@deathbob

There are other ways to get around it, which are all probably easier for everyone than going to the trouble of assigning a different parameter to find the resource by, but google led me here for a similar issue.

after uploading a video, youtube directs you back to a url of your choosing, with query string like
"?status=200&id=CmMU8MXikls". This overrides the default :id parameter, so if your route is like /posts/:id/upload_finished?status=200&id=CmMU8MXikls it will try and find a post with id = CmMU8MXikls.

I went with load_and_authorize_resource :except => [:upload_finished] as the solution which works fine, but wanted to note that there could be a legitimate reason why params[:id] was not the right thing to find the record by.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment