title: Rails redirect_to REST
body: <p>I'm in the process of learning RoR, and I'm liking everything that I'm discovering so far. I'm switching over from the PHP-based CodeIgniter framework, and I have a problem in using the <strong>redirect_to</strong> method.</p>
  
  <p>I've defined a basic Users model which I use to handle registration - data gets stored fine in the DB, but the problem is when redirecting after signing up a user to the system.</p>
  
  <p>Basically, the profile page is of the following format: <strong>/users/:name/:id</strong></p>
  
  <p>I have a routes file defined as such:</p>
  
  <pre><code>resources :users
  match '/users/:name/:id', :to =&gt; 'users#show'
  </code></pre>
  
  <p>And here is my <strong>create</strong> method</p>
  
  <pre><code>def create
    @title = "User creation"
  
    @user = User.new(params[:user])
    if @user.save
      info = { :name =&gt; @user.name, :id =&gt; @user.id }
  
      redirect_to info.merge(:action =&gt; "show")
    else
      @title = 'Sign Up'
      render 'new'
    end
  end
  </code></pre>
  
  <p>However this will generate an url of the following format:</p>
  
  <pre><code>http://localhost:3000/users/27?name=Testing
  </code></pre>
  
  <p>When I'm actually looking for something like this: </p>
  
  <pre><code>http://localhost:3000/users/Testing/27
  </code></pre>
  
  <p>It just makes sense for me from a SEO point of view that a profile page URL look like that. I've been searching the inter-webs, but I only find solutions to different problems. I hope someone can help.</p>
  
  <p><strong>SOLVED</strong>
  Both versions that were suggested by Ryan worked fine, and I decided to stick to the second one, since it feels more RESTful. I'll just share the config I have right now - mind you, the User model may not be all that correct, but it's the to_param function that's important. Also, I've noticed that it doesn't work if I make the function <em>private</em> - that makes sense, but I just thought that I'd share that for someone that may be running into that sort of problem.</p>
  
  <p>Here's my routes file:</p>
  
  <pre><code>resources :users
  </code></pre>
  
  <p>And here is my Users model:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    attr_accessible :name, :email
  
    email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  
    validates :name, 
        :presence =&gt; true,
        :length =&gt; { :within =&gt; 5..50 }
  
    validates :email,
        :presence =&gt; true,
        :format =&gt; { :with =&gt; email_regex},
        :uniqueness =&gt; { :case_sensitive =&gt; false }
  
    def to_param
      "#{id}-#{name.parameterize}"
    end
  end
  </code></pre>
  
  <p>And here's my controller <strong>create</strong> function:</p>
  
  <pre><code>def create
    @title = "User creation"
  
    @user = User.new(params[:user])
    if @user.save
      redirect_to @user
    else
      @title = 'Sign Up'
      render 'new'
    end
  end
  </code></pre>