-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Feb 3, 2012, at 3:13 PM, Srimanta Chakraborty wrote: > Prince Joseph wrote in post #1043906: >> @Michael is right. We can help you in doing this, in case you are stuck >> up >> somewhere, but you must really atleast make an effort. >> >> As of point 3, you can consider the following suggestions: >> >> 1. `current_user.roles.map {|r| r.to_s}.include?('admin')` >> >> Consider moving this code to User model by defining an instance >> function >> like 'admin?' so that you can call 'current_user.admin?' >> 2. `@info = Info.find(:first, :conditions => "article_id = >> #{@article.id}")` >> >> Use associations to define this so that you call `@info = >> @article.info` >> 3. `@comments = Comment.find(:first, :conditions => "article_id = >> #{@article.id}")` >> >> Again use associations for this. Also, since this is returning a >> single >> object, the variable name should be @comment (singular). >> >> >> >> On Fri, Feb 3, 2012 at 5:08 PM, Michael Pavling <pavl...@gmail.com> >> wrote: >> >>>> Thanks for your compliment. But please... >>> You received this message because you are subscribed to the Google Groups >>> "Ruby on Rails: Talk" group. >>> To post to this group, send email to rubyonrails-talk@googlegroups.com. >>> To unsubscribe from this group, send email to >>> rubyonrails-talk+unsubscr...@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/rubyonrails-talk?hl=en. >>> >>> >> >> >> -- >> Thanks, >> Prince > > Thanks for your hint, I have tried the problem and please check this > whether it is correct or not > > Models requires: > class Article < ActiveRecord::Base > has_many :related_articles, :dependent => :destroy > has_many :info, :dependent => :destroy > has_many :comments, :dependent => :destroy > end > class RelatedArticle < ActiveRecord::Base > belongs_to :article > end > class Info < ActiveRecord::Base > belongs_to :article > end > class Comment < ActiveRecord::Base > belongs_to :article > end > > Each article can be related to many articles (or none). -- YES > > > Cleaning up the code: > > class ArticleController < ApplicationController > def show > @article = Article.find(params[:id]) > if current_user.roles.map {|r| r.to_s}.include?('admin') > @info = @article.info.first > else > @info = nil > end > if params[:show_comments] && params[:show_comments] != '' > @comments = @article.comments.first > end > if !(params[:hide_related] && params[:hide_related] != '') > @related_articles = @article.related_articles > end > end > end > > -- > 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 post to this group, send email to rubyonrails-talk@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > Dud i will give you 2 hints : - - RTFM - - try .blank? method # if params[:show_comments] && params[:show_comments] != '' can be wrote as unless params[:show_comments].blank? Alecslupu -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.17 (Darwin) Comment: GPGTools - http://gpgtools.org iQEcBAEBAgAGBQJPLGd0AAoJEAa2YjEk8CRGW6cIAJD3PdHXOTFUYFrN7lVWlKSh h+Pj1kBAPqUfJqaRDYP+QeJZgyRqcHDd9e9iRZqDLvwjAT369Uk7kB79aTHRjhKh gzlwtyJhG6OaRSguyO29qba6ofXaX63G1T01u+FpWWx5LdsxilGwgXqVL+tdZqoE CbUq2CjUWpIUTQ6ILlutAWUUNH7UtUlsteeBrAtWRR2uGB1LIBN0/0HnxCxmKA0X mSltDek0aAJy8A+368s3TYxZa1Ed4oLjdxaF4Pfvd7mfIAXsLnd8S7RwN5YatToP Mv5envrYNjIymmb8lwnLigoFnwSX8tR8xTnDMFT3patVgvRPnykpJcKU4QcgZoc= =tuad -----END PGP SIGNATURE----- -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.