Dear all, I would like to save a restful resource in the database, and display it as a link on the web page. I tried saving: bar_path(1) into the path column in the table, but unfortunately it doesn''t work when I display it like this: <%= link_to ''bar'', bar.path %> Is this possible with rails? Thank you very much in advance for your help. Kind regards, Joshua -- http://twitter.com/scrum8 -- http://twitter.com/scrum8 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Should be possible. When you call bar_path(1) it just returns a string like "/bar/1" which you can then save in the database. Can you clarify what "it doesn''t work" means when you try this: <%link_to ''bar'', bar.path %>. Do you get an error? Does it just not output what you expect? That should work for GET requests. If you wanted to link to another method, you''ll have to specify that since it''s not part of the path: < %= link_to ''bar'', bar.path, :method => :delete %> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Tim, Thank you for the response. Currently it display the plain text of the route method: bar_path(1) instead of: /bar/1 When I looked in the database it saved as String. Do I need to convert it into a method? Sorry for the vague question and thanks heaps for your help. Kind regards, Joshua On May 18, 10:57 pm, Tim Shaffer <t...-PGA7PSC7mq/3MY4plGdlAw@public.gmane.org> wrote:> Should be possible. When you call bar_path(1) it just returns a string > like "/bar/1" which you can then save in the database. > > Can you clarify what "it doesn''t work" means when you try this: <%> link_to ''bar'', bar.path %>. Do you get an error? Does it just not > output what you expect? > > That should work for GET requests. If you wanted to link to another > method, you''ll have to specify that since it''s not part of the path: < > %= link_to ''bar'', bar.path, :method => :delete %> > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.