Displaying 2 results from an estimated 2 matches for "news_category".
Did you mean:
new_category
2006 Jul 03
0
Modelling Relationships as objects
...cord::Base
has_many :subscriptions
has_many :news_categories, :through => :subscriptions
end
class NewsCategory < ActiveRecord::Base
has_many :subscriptions
has_many :users, :through => :subscriptions
end
class Subscription < ActiveRecord::Base
belongs_to :user
belongs_to :news_category
end
User and NewsCategory(2 tables in database) have m:n relation and hence they
would require another db table to represent the
relationship.(User_NewsCategory); now they r 2 ways to model these objects
and relations in Rails,
1. Use habtm with 2 models for 2 db tables.
2. Use has_many :through...
2007 Jul 19
7
NoMethodError in partial driving me mad
...tial ''news''
end
def show_category
@news = NewsCategory.find(params[:id]).news
render_partial ''news'', :collection => @news
end
_news.rhtml:
---------------------------------
<div>
<h1><%=h news.title %> - Kategory: <%= news.news_category.title %></
h1>
<p>
<%= bbcodeize news.content %>
</p>
<p>
<span class="author">
erstellt von <%=link_to news.user.login, :controller =>
"user", :action => "show", :id => news.user.id %>
vor <%= time_ag...