Autogenerate Link List (Painfully Newbie)

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 :

<–

    <% for link in Article.link_columns %>
  • <%=h article.send(link.name) %>
  • <% end %>

—>

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?

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 :

<–

    <% for link in Article.link_columns %>
  • <%=h article.send(link.name) %>
  • <% end %>

—>

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:

    <% @articles.each do |article| %>
  • <%= article.link %>
  • <% end %>

If you want to actually link to the article, look up the link_to
function.

    <% for article in @articles %>
  • <%= link_to(article.title, :controller => 'articles', :action => 'show', :id => article.id, :link => article.link) %>
  • <% end %>

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