# Setting variable via url

**URL:** <https://www.ruby-forum.com/t/setting-variable-via-url/104692>\
**Category:** Rails\
**Created:** [May 21, 2007, 5:21pm UTC](https://www.ruby-forum.com/t/setting-variable-via-url/104692 "2007-05-21T17:21:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [May 21, 2007, 5:21pm UTC](https://www.ruby-forum.com/t/setting-variable-via-url/104692/1 "2007-05-21T17:21:23Z")

</div>

Hi all,

One of my routes looks like this: map.connect  
‘:blog/:controller/:action/:id’

The :blog should actualy become a session variable (indication who’s  
blog it is). eg url: [Custom Application Development Software for Business - Salesforce.com](http://www.site.com/railsblog/posts/) I want to set a  
session variable to ‘railsblog’. Is this possible? If yes, how do I do  
this?

Thanks in advance  
Stijn

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [May 21, 2007, 7:25pm UTC](https://www.ruby-forum.com/t/setting-variable-via-url/104692/2 "2007-05-21T19:25:38Z")

</div>

In your example, params[:blog] has the value ‘railsblog’, so you  
could do session[:blog] = params[:blog] to set a session variable  
with that value.

–  
Building an e-commerce site with Rails?  
[http://agilewebdevelopment.com/rails-ecommerce](http://agilewebdevelopment.com/rails-ecommerce)

Meet up at RailsConf:  
[http://railsconf2007.conferencemeetup.com/](http://railsconf2007.conferencemeetup.com/)

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [May 22, 2007, 10:18am UTC](https://www.ruby-forum.com/t/setting-variable-via-url/104692/3 "2007-05-22T10:18:21Z")

</div>

With every request I should set that blog parameter to the session  
variable. I tried to add session[:blog] = params[:blog] in the  
ApplicationController but this doesn’t work (‘We’re sorry, but  
something went wrong.’). Isn’t the AppliationController always called  
and isn’t it thus the perfect place to set that session variable?

Thanks in advance  
Stijn
