Hello, I have a problem with link_to, this is my code <% if @categories for category in @categories link_to "test", "http://www.rubyonrails.org/" end end %> But this doesn''t output anything to the screen, but with the below code, it output the text inside the block. <% if @categories for category in @categories %>test <% end end %> I''m using link_to in the wrong way or ??? Hope someone can help me out, and thanks :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Jamal, You need to use link_to like this: <%= link_to "test", "http://www.rubyonrails.org/" %> instead of what you are doing: <% link_to "test", "http://www.rubyonrails.org/" %> In your example you could do the following: <% if @categories for category in @categories %> <%= link_to "test", "http://www.rubyonrails.org/" %> <% end end %> or <% if @categories for category in @categories puts link_to "test", "http://www.rubyonrails.org/" end end %> HTH, Mischa -- http://boxroom.rubyforge.org Jamal Soueidan wrote:> Hello, > > I have a problem with link_to, this is my code > > <% > if @categories > for category in @categories > link_to "test", "http://www.rubyonrails.org/" > end > end > %> > > But this doesn''t output anything to the screen, but with the below code, > it output the text inside the block. > > <% > if @categories > for category in @categories > %>test <% > end > end > %> > > I''m using link_to in the wrong way or ??? > > Hope someone can help me out, and thanks :)-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I would like to use the "puts" => but it doesn''t output anything? The = is working good but I don''t like to open and close %> all the time if I need to use <% -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You''re right "puts" doesn''t work. One suggestion -- to make it look more clean -- is that you make sure in the controller that @categories is not nil (instead of in the view). If you do that the code in your view could look like this: <% for category in @categories -%> <%= link_to "test", "http://www.rubyonrails.org/" %> <% end -%> Cheers, Mischa -- http://boxroom.rubyforge.org -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---