# Newb's quick question on session variable vs. params in 'pretty' urls

**URL:** <https://www.ruby-forum.com/t/newbs-quick-question-on-session-variable-vs-params-in-pretty-urls/187029>\
**Category:** Rails\
**Created:** [April 15, 2010, 11:38pm UTC](https://www.ruby-forum.com/t/newbs-quick-question-on-session-variable-vs-params-in-pretty-urls/187029 "2010-04-15T23:38:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![grar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cc9497/32.png) [@grar](https://www.ruby-forum.com/u/grar)\
**Post date:** [April 15, 2010, 11:38pm UTC](https://www.ruby-forum.com/t/newbs-quick-question-on-session-variable-vs-params-in-pretty-urls/187029/1 "2010-04-15T23:38:19Z")

</div>

Hi,

Is there a compelling reason to prefer reliance on the params hash vs.  
the same info stored in a session hash? So, for example, params[:id] =  
@loan vs. session[:loan\_id] = @loan.id? It matters because I can make  
prettier urls if I store certain uniquely identifying model attributes  
as session variables.

The drawback I can think of in preferring session variables to the  
params hash is that a user cannot be guaranteed to recover via the  
same url the same model instance under the session-preferred approach,  
because the session variable may have changed.

Thanks for any comment,

Grar

---

<div class="post-metadata">

**Author:** ![grar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cc9497/32.png) [@grar](https://www.ruby-forum.com/u/grar)\
**Post date:** [April 16, 2010, 8:11pm UTC](https://www.ruby-forum.com/t/newbs-quick-question-on-session-variable-vs-params-in-pretty-urls/187029/2 "2010-04-16T20:11:27Z")

</div>

On Apr 15, 2010, at 2:37 PM, Grary wrote:

> params hash is that a user cannot be guaranteed to recover via the  
> same url the same model instance under the session-preferred approach,  
> because the session variable may have changed.
> 
> Thanks for any comment,
> 
> Grar

Server farms are one reason, but with cookie-based session store, it’s  
not that big a deal. The other reason that comes to mind is Web  
crawling. Relying on session state often defeats Web crawlers, although  
that does not seem like it’s relevant to the example you gave. Why can’t  
you make load\_id part of the URL using routing?

---

<div class="post-metadata">

**Author:** ![grar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cc9497/32.png) [@grar](https://www.ruby-forum.com/u/grar)\
**Post date:** [April 18, 2010, 8:22pm UTC](https://www.ruby-forum.com/t/newbs-quick-question-on-session-variable-vs-params-in-pretty-urls/187029/3 "2010-04-18T20:22:04Z")

</div>

This is, then, a perfect use for session.

---

<div class="post-metadata">

**Author:** ![grar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cc9497/32.png) [@grar](https://www.ruby-forum.com/u/grar)\
**Post date:** [April 17, 2010, 4:17pm UTC](https://www.ruby-forum.com/t/newbs-quick-question-on-session-variable-vs-params-in-pretty-urls/187029/4 "2010-04-17T16:17:09Z")

</div>

Steve,

I’m persisting a ‘transitional’ object through a few views, spawning  
descendants from it and then deleting the parent object. In this case,  
then, it doesn’t seem to make sense to publicize a reference to the  
transitional object in a url because the referenced object will not be  
persisted indefinitely – indeed its creation should be silent to the  
user.

Grar
