Forum: Ruby on Rails path from db as string not evaluated

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Heinz S. (Guest)
on 2009-03-04 14:21
Hey,

my menu is stored in the database like that:
name       path
Home       root_path
Users      users_path

and I create the links with link_to_remote:
<%= link_to_remote navigation.name,
  :url => navigation.target,
  :update => 'contentBody',
  :method => :get %>

The problem is when I load page it looks like:
<a onclick="new Ajax.Updater('contentBody', 'users_path',
{asynchronous:true, evalScripts:true, method:'get'}); return false;"
href="#">Users</a>

Does anyone know how to evaluate that users_path so it's /users instead?
Heiszmann L. (Guest)
on 2009-07-31 13:40
Hy!

I have a same problem and I think the to_sym method is the solution.
If you would insert users_path into he link_to attributes, you need
"users".to_sym.

Examples:
   "new_user".to_sym => new_user_path
   "root".to_sym => root_path

And it's work.

Sorry for my bad english.



Heinz S. wrote:
> Hey,
>
> my menu is stored in the database like that:
> name       path
> Home       root_path
> Users      users_path
>
> and I create the links with link_to_remote:
> <%= link_to_remote navigation.name,
>   :url => navigation.target,
>   :update => 'contentBody',
>   :method => :get %>
>
> The problem is when I load page it looks like:
> <a onclick="new Ajax.Updater('contentBody', 'users_path',
> {asynchronous:true, evalScripts:true, method:'get'}); return false;"
> href="#">Users</a>
>
> Does anyone know how to evaluate that users_path so it's /users instead?
This topic is locked and can not be replied to.