Henrik Ormåsen
2006-Jan-30 14:00 UTC
[Rails] Howto change @article.article.headline to @article.headline ?
I have to actions:
def index
@articles = Article.find(:all,
:conditions => "un_published != ''1''",
:order => "created_on desc")
end
and
def group
id = params[:id]
@articles = ArticleGroup.find(:all,
:include => [:group, :article],
:conditions => ["articles.un_published != ''1''
and groups.id ?", id],
:order => "articles.created_on desc")
render :action => ''index''
end
The last one will not work off course, because in the index.rhtml view
I get the stuff from the array with @article.headline,
@article.ingress etc. and in the group action I have to use
@article.article.headline etc. I really don''t want to write another
view just because of this difference.
How can I avoid it?
Regards.
Henrik Orm?sen
Henrik Ormåsen
2006-Jan-30 19:58 UTC
[Rails] Howto change @article.article.headline to @article.headline ?
I have to actions:
def index
@articles = Article.find(:all,
:conditions => "un_published != ''1''",
:order => "created_on desc")
end
and
def group
id = params[:id]
@articles = ArticleGroup.find(:all,
:include => [:group, :article],
:conditions => ["articles.un_published != ''1''
and groups.id ?", id],
:order => "articles.created_on desc")
render :action => ''index''
end
The "render :action" in the last one will not work off course, because
in the index.rhtml view I get the stuff from the array with
@article.headline, @article.ingress etc. and in the group action I
have to use @article.article.headline etc. I really don''t want to
write another view just because of this difference.
How can I avoid it?
Regards.
Henrik
Jonathan Viney
2006-Jan-31 05:48 UTC
[Rails] Re: Howto change @article.article.headline to @article.headl
The simplest way is to define a headline method on ArticleGroup def headline article.headline end -Jonny.> > The "render :action" in the last one will not work off course, because > in the index.rhtml view I get the stuff from the array with > @article.headline, @article.ingress etc. and in the group action I > have to use @article.article.headline etc. I really don''t want to > write another view just because of this difference. > > How can I avoid it? > > Regards. > Henrik-- Posted via http://www.ruby-forum.com/.
albert ramstedt
2006-Feb-06 13:23 UTC
[Rails] Howto change @article.article.headline to @article.headline ?
If you want to use the exact same view, then I assume you just need the
Article objects. Then I would change your group action like this:
def group
id = params[:id]
article_groups = ArticleGroup.find(:all,
:include => [:group, :article],
:conditions => ["articles.un_published != ''1''
and groups.id ?", id],
:order => "articles.created_on desc")
@articles = article_groups.collect {|a| a.article}
render :action => ''index''
end
cheers
Albert
Henrik Orm?sen wrote:
>I have to actions:
>
> def index
> @articles = Article.find(:all,
> :conditions => "un_published !=
''1''",
> :order => "created_on desc")
> end
>
>and
>
> def group
> id = params[:id]
> @articles = ArticleGroup.find(:all,
> :include => [:group, :article],
> :conditions => ["articles.un_published !=
''1'' and groups.id > ?", id],
> :order => "articles.created_on desc")
> render :action => ''index''
> end
>
>The "render :action" in the last one will not work off course,
because
>in the index.rhtml view I get the stuff from the array with
>@article.headline, @article.ingress
>
> etc. and in the group action I
>have to use @article.article.headline etc. I really don''t want to
>write another view just because of this difference.
>
>How can I avoid it?
>
>Regards.
>Henrik
>_______________________________________________
>Rails mailing list
>Rails@lists.rubyonrails.org
>http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
>