My Index Controller:
class IndexController < ApplicationController
def index
@posts = Post.find(:all, :limit => 10,
:joins => "LEFT JOIN `users` ON users.user_id = posts.user_id",
:select => "posts.*, users.username",
:order => "posts.created_at DESC")
end
end
How can i access the users.username from the view?
I tried
<% @posts.each do |post| %>
<%= post.username %>
<% end %>
but it doesn’t seem to work since i get a blank message…
EDIT:
i had to use the following code in the LEFT JOIN:
:joins => "LEFT JOIN `users` ON posts.user_id = users.id",
i had to use the following code in the LEFT JOIN: