Reputation: 3390
I'm a Rails noob and I'm following a blog post I found here...
I have everything working up until the end. Then things get nebulous.
So if I have this in my helper...
module ApplicationHelper
def display_content_with_links(tweet)
tweet.content.gsub(/(http:\/\/[a-zA-Z0-9\/\.\+\-_:?&=]+)/) {|a| "<a href=\"#{a}\">#{a}</a>"}
end
end
Shouldn't I be able to have my tweets display in my view with this...
What am I doing wrong?
Upvotes: 1
Views: 290
Reputation: 5096
Actually, you should add
@tweet = Tweet.all
To the controller#action you have setup already, then iterate over them in your view:
<ul>
<% @tweets.each do |tweet| %>
<li><%= display_content_with_links tweet %></li>
<% end %>
</ul>
Upvotes: 0
Reputation: 4376
You are going to need a controller and view to have this display. Something simple like:
# app/controller/tweets_controller.rb
TweetsController < ApplicationController
def index
@tweets = Tweet.get_latest
end
end
and in the view:
# app/views/tweets/index.html.haml
%ul
- @tweets.each do |tweet|
%li
= display_content_with_links tweet
or if you use erb
# app/views/tweets/index.html.erb
<ul>
<% @tweets.each do |tweet| %>
<li>
<%= display_content_with_links tweet %>
</li>
<% end %>
</ul>
This is a pretty basic example that might not even come close to what you want, but it should point you in the right direction.
Upvotes: 3