In a classic Rails application it’s typical to have a route similar to this

http://localhost:8000/model/1

In the controller this translates to this:

def show
  @model = Model.find(params[:id])
end

But in some cases you may want to render something based on a users session. Maybe you have a currently edited file or a profile item you need to bring in. If you have an available session to query on you can do this.

def show
  @model = Model.find_by_url(current_user_session.url)

The cool part about this, is now you can have a url in a show action render anything and as long as the session is active the user will only see their active session information.

http://localhost:8000/model/anything_you_want

:)

Leave a Reply

Your email address will not be published. Required fields are marked *