a view of two models

I have two models which are related by a foreign key. I would like to have a report along the lines of:

call_comment login

I have two models which are related by a foreign key. I would like to have a report along the lines of:

call_comment login

first 1234

From sqlite, it looks like so:

SELECT calls.comment,logins.login FROM calls,logins WHERE

calls.login_id=logins.id; first>1234 second>0123 first>1234

But, of course, I'd like to do that from Ruby on Rails :slight_smile:

thanks,

Thufir

This screencast might help

I get sound for mp3's, but not for that screencast :frowning:

It's helpful, but my controller looks quite different from his (probably deprecated?). In my controller, I want something like:

@calls=Call.find(:all, :include => [:logins, :login])

Is that right? Do I create a new method?

thufir@arrakis ~/goodfellow-tool $ thufir@arrakis ~/goodfellow-tool $ cat -n app/controllers/ calls_controller.rb | head -n 5 | tail -n 4      2 def index      3 list      4 render :action => 'list'      5 end thufir@arrakis ~/goodfellow-tool $ rails --version Rails 1.2.5 thufir@arrakis ~/goodfellow-tool $

thanks,

Thufir

Do you have   belongs_to :login In you Call model?

if so, then you should be able to do this in your CallController   def index     @calls = Call.find(:all)   end

and this in your view (index.rhtml or index.html.erb under app/views/ call/) <table>   <tr>     <th>call_comment</th>     <th>login</th>   </tr>   <% for call in @calls %>     <tr>       <td><%= call.comment %></td>       <td><%= call.login.login %></td>     </tr>   <% end %> <table>

if you want to reduce the number of database calls, change this     @calls = Call.find(:all) to this     @calls = Call.find(:all, :include => :login)

doing that is not necessary though.

Hope that helps

perhaps not, but it's good to know different ways of doing things!

I believe that I have the models/relationships configured correctly, but I haven't had a chance to play with rails in a while :frowning:

My gentoo system is all screwed up, I can't get ruby working :frowning:

-Thufir