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
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:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.