Ruby on Rails: Getting a route with Devise -


tl;dr how can achieve return routes devise user model id in custom controllers (i.e. redirecting localhost:3000/profiles/504026426) mongoid?

i have project has social profile controller returns of user id devise complain mongoid needs valid id number in order work route: localhost:3000/profiles/.

# let's want return route id (devise) without having # rails complain mongoid needs id of number.  # so, have controller containing profiles in files. # goes like.. class profilescontroller < applicationcontroller   before_filter :authenticate_user!     # /profile/     def index       @user = user.find(params[:id])     end     # .. snipped brevity. end 

is right way it?

firstly, 'params[:id]' you're trying find user won't work in index view, because you're not passing in parameter via url ('profiles/:id' or: localhost:3000/profiles/504026426). if want store user available in index view, use sessions , current user helper method. see here.

if want method work 'params[:id]' like:

get 'profile/:id' => 'profiles#show' 

make sure matches show function in controller

def show   # work with: localhost:3000/profiles/504026426      @user = user.find(params[:id]) end 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -