Ruby on Rails Tuesday, April 12, 2016

Hi,

Using rails 4, I have two models Supplier and Category

Category belongs_to Supplier

and Supplier has_many categories


now the suppliers table has fields, company_name, address, phone etc.
and id

and the categories has cat_name and supplier_id

in the categories index view I want to display all categories names
along with associated company_names.

in the categories_controller my index method is below.

def index
@categories = Category.all
#????????????????????? what to do to find company_name
end

and my index.html.erb view is

<% @categories.each do |category| %>
<tr>
<td><%= category.cat_name %></td>
<td><%= category.cat_sub_name %></td>
<td><%= category.supplier %></td>
<td><%= link_to 'Show', category %></td>
<td><%= link_to 'Edit', edit_category_path(category) %></td>
<td><%= link_to 'Destroy', category, method: :delete, data: {
confirm: 'Are you sure?' } %></td>
</tr>
<% end %>


I have no idea how to this. pls help.

--
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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/de682fdaa1785bf9e4e3d86685668628%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment