I''m struggleing in the early stages of learning RoR. I''m playing around with a simple blog format. I''m already stuck. What I am trying to do is iterate over the titles of articles in my database, and list them. The article table has rows id, link, title, content. "Link" is actually what I would be using, incase I had a title that I thought was too long to make into a link, I would put a shorter version into the "link" row. I imagine it must be something along the lines of : <-- <ul> <% for link in Article.link_columns %> <li><%=h article.send(link.name) %></li> <% end %> </ul> ---> Of course, a: that doesn''t work, and b: that wouldn''t generate clickable links, but it''s all I have at the moment. Any suggestions? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> What I am trying to do is iterate over the titles of articles in my > database, and list them. The article table has rows id, link, title, > content. "Link" is actually what I would be using, incase I had a > title that I thought was too long to make into a link, I would put a > shorter version into the "link" row. > > I imagine it must be something along the lines of : > > <-- > > <ul> > <% for link in Article.link_columns %> > <li><%=h article.send(link.name) %></li> > <% end %> > </ul> > > ---> > > Of course, a: that doesn''t work, and b: that wouldn''t generate > clickable links, but it''s all I have at the moment. > > Any suggestions?In your controller method, you should have something that looks like this: @articles = Article.find(:all) then in your view something like this: <ul> <% @articles.each do |article| %> <li><%= article.link %></li> <% end %> </ul> If you want to actually link to the article, look up the link_to function. -- 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 -~----------~----~----~----~------~----~------~--~---
<ul> <% for article in @articles %> <li><%= link_to(article.title, :controller => ''articles'', :action => ''show'', :id => article.id, :link => article.link) %></li> <% end %> </ul> you need something like this in config/routes.rb map.connect ''/articles/show/:id/:link'', :controller => ''articles'', :action => ''show'', :id => nil, :link => nil -- Heri R. http://sprinj.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 -~----------~----~----~----~------~----~------~--~---