I accidently sent my email before I was finished (no tab in gmail!)
I have the following setup...
Articles
* id
* title
* body
* user_id
Categories
* id
* name
articles_categories
* article_id
* category_id
* position
The idea is that an article could be in multiple categories with various
sorts for each category. So if article a in is category a it might be in
position 1 while article a could be in position 5 in category b...make
sense?
1) Is there a native, DRY, way to handle this?
2) Assuming there is not, what might be a second option.
I know there are several ways to accomplish this, but being somewhat new to
RoR, I''m curious as to the "proper" way to handle this
situation. Currently,
I''m attempting the following
def add_article
article=Article.new
article.title=params[:title]
article.body=params[:body]
category=Category.find_by_sql("select a.*,case max(position) when null
then 0 else max(position)+1 end as last_article from categories a inner join
articles_categories b on a.id=b.category_id where a.id=#{catid} group by
a.id <http://a.id>")
article.categories.push_with_attributes(category,:position=>
category.last_article)
end
however, it blows up. And, since I haven''t gotten to the debug stage
of RoR
yet, I have now idea why.
Thanks,
Matt
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails