1

routes.rb:

match 'first/#!/:name' => 'first#first'

first_controller.rb:

class FirstController < ApplicationController
  def first
    @name = params[:name]
  end
end

But the @name variable is nil when I render the url: http://localhost:3000/first/#!/sayuj

Please help

2
  • 2
    Hash-bang URLs are usually used by JavaScript for routing, not for server-side routing. Why are you doing it like that? Commented Jun 1, 2011 at 15:01
  • I agree with Skilldrick. I think there is some XY syndrome going on here. Can you elaborate as to why you need to use hashbang URLs? Commented Jun 1, 2011 at 15:11

2 Answers 2

10

Anything after the first # in the URL is not (usually) sent back to the server; it's used on client side only.

So the URL http://localhost:3000/first/#!/sayuj in the client will actually call the URL http://localhost:3000/first/ on server side.

See the following posts for more info:

Sign up to request clarification or add additional context in comments.

Comments

1

Jits is correct that the # in the url will drop the rest of the url, also, I believe your route is incorrect, it should look like:

match 'first/:name', :to => 'first#first'

documentation is at Engine yard rails 3 routes.

2 Comments

Rails 3 routing supports shorthand that will let his existing code work. Saying match 'first/:name' => 'first#first' is fine. Also if he were using a name method in FirstController the other shorthand method could be used to say simply: match 'first/name' and rails with link it up accordingly.
Thanks for the info, I did not know you could shorthand that even further.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.