Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

link_to not working in script/console

// using Rails 2.3.5

//routes.rb
map.resources :users, 

>> user = User.first
>> helper.link_to user.name, user

I am getting nil error. I thought the above code should work. What am I missing?

like image 524
Nick Vanderbilt Avatar asked Apr 08 '10 15:04

Nick Vanderbilt


1 Answers

The problem is that link_to uses url_for which needs an incoming url host. You can use app.url_for in the console to fake it like so:

helper.link_to user.name, app.url_for(user)
like image 134
mckeed Avatar answered Sep 27 '22 16:09

mckeed