Вопрос по ruby-on-rails, ruby-on-rails-3 – Показывать имя вместо идентификатора в таблице представления has_many

3

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

#Posts model
belongs_to :categories  

#Category model
has_many :posts

Error: User Rate Limit Exceeded

@categories = @posts.Category.find(:all, :order => 'categoryname')

Error: User Rate Limit Exceeded

<% @posts.each do |post| %>
<tr>
<td><%= post.category_id %></td>
<td><%= @categories.categoryname %></td>

<td><%= link_to 'View', post %></td>
<td><%= link_to 'Edit', edit_post_path(post) %></td>
</tr>
<% end %>

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

<td><%= post.categories.categoryname %></td>

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

<td><%= post.category.categoryname %></td>

Error: User Rate Limit Exceeded

Ваш Ответ

5   ответов
4

Error: User Rate Limit Exceeded

belongs_to :categories  

Error: User Rate Limit Exceeded

belongs_to :category 

Error: User Rate Limit Exceeded

@post.category.categoryname

Error: User Rate Limit Exceeded

#Post
has_and_belongs_to_many :categories

#Category
has_and_belongs_to_many :posts

Error: User Rate Limit Exceededcategories_postsError: User Rate Limit Exceededcategory_idError: User Rate Limit Exceededpost_idError: User Rate Limit Exceeded

@post.categories.each do |cat|
  cat.categoryname
end

Error: User Rate Limit Exceeded

@categories = @posts.Category.find(:all, :order => 'categoryname')

Error: User Rate Limit Exceeded

11

Error: User Rate Limit Exceeded

belongs_to :category

Error: User Rate Limit Exceeded

<td><%= post.category.categoryname %></td>

Error: User Rate Limit Exceeded@categories =Error: User Rate Limit Exceeded

Error: User Rate Limit Exceededname. post.category.nameError: User Rate Limit Exceededpost.category.categorynameError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded Gabe M
Error: User Rate Limit Exceeded Gabe M
0

2

undefined method `categoryname' for nil:NilClass on the line: <%= post.category.categoryname %>

0

Error: User Rate Limit Exceeded(as you mentioned in your comment)Error: User Rate Limit Exceeded

if post.category_id?

Error: User Rate Limit Exceeded

<td><%= post.category.categoryname if post.category_id? %></td>

Error: User Rate Limit Exceeded

Похожие вопросы