ruby on rails - Devise: How to prevent users from seeing other users information -


when user logged in has ability see events attending. action in users controllers following

class userscontroller < applicationcontroller   before_filter :authenticate_user!    def events     @title = "events"     @event = user.find(params[:id])     @events = @event.event_presence.paginate(page: params[:page])     render 'show_events'   end end 

however user(2) able see events of user(3) changing http adress from: /users/2/events users/3/events

so question is, how can make sure user(2) able see events of user(2) , not of user(3).

thanks

filter on current_user.id in events method instead of params[:id]

@event = user.find(current_user.id) 

however, better way have special route doesn't include id

get 'events' => 'users#events', as: :users_events 

and use so

= link_to 'events', users_events_path 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -