1. Provide the models required
2. Each article can be related to many articles (or none).Provide code
for making @article.related_articles work
3. Clean up the code according to rails conventions
class ArticleController < ApplicationController
def show
@article = Article.find(params[:id])
if current_user.roles.map {|r| r.to_s}.include?('admin')
@info = Info.find(:first, :conditions => "article_id =
#{@article.id}")
else
@info = nil
end
if params[:show_comments] && params[:show_comments] != ''
@comments = Comment.find(:first, :conditions => "article_id =
#{@article.id}")
end
if !(params[:hide_related] && params[:hide_related] != '')
@related_articles = @article.related_articles
end
end
end
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).
> 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+unsubscribe@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
Not if you read it thus:
"I don't l know why you waste your time on this loser."
But it's a bit of a strong judgement for my tastes... personally, I
think he's a bit of a chancer, trying to get better grades by getting
people to do his work for him. Wouldn't go so far as to bandy around
insults.
I agree that insults in general are bad. This rare time it seemed deserved.
A few questions are fine. Being a chump for someone who won't do their homework is beyond the pale. Programmers don't always have good local resources for help. As a student, he should have a professor, TA, fellow students to lean on.
I just think in this case we're being played. Certainly 'nuff said on this "chancer" (whatever that is :-)) for now.
<a two-faced chancer, he doesn't hesitate to dump people when they
are no longer of any use>
<betrayed by a chancer who, she mistakenly thought, was her friend>
Hi,
I am a new guy in ruby on rails. I am using this forum to get help
to learn this. So please don't think that I am a loser or chancer. In
this world everybody tries to get chance. If you don't want to help then
just ignore it.