dimanche 12 février 2017

Rails - Find by username and post id

Vote count: 0

In my posts controller, right now I'm finding posts by user_id and a slug and it works perfectly fine

    def find_post
        @track = Track.find_by(user_id: params[:id], slug: params[:slug])
    end

I am looking for a way to find the post instead of the user_id, by the username for example if it's finding the post like this:

/:user_id/:slug

To something like:

/:username/:slug

So how can I access the username parameter in the url? or is there a better process for this?

asked 41 secs ago

Let's block ads! (Why?)



Rails - Find by username and post id

Aucun commentaire:

Enregistrer un commentaire