Forum: Ruby on Rails Save the current article id

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
37fa021ceb617276328f0c6af1c3da81?d=identicon&s=25 Stefano Bortolotti (mex23)
on 2007-05-20 18:36
Hi guys, I want to save the current article id, but I don't know how.
someone have an example?
Ex. I click on "show article", after that I click "edit article". When
the editing is finished I want to click "back" and loading the show page
with the previous article.
6d57db44c5a4e0721cc7f78cf0ce308a?d=identicon&s=25 Stephen Bartholomew (steveb)
on 2007-05-20 19:08
(Received via mailing list)
Hey,

Depending on your code, you should be able to just do @article.id in
your view to access the current article's id.  For a route you can
even drop the .id:

<%= link_to 'Edit this article', :action => 'edit', :id => @article %>

and if you're using map.resources, it's even shorter:

<%= link_to 'Edit this article', edit_article_path(@article) %>

Hope that helps,

Steve
37fa021ceb617276328f0c6af1c3da81?d=identicon&s=25 Stefano Bortolotti (mex23)
on 2007-05-20 19:26
I don't want to access to the current article.id but save it in the
class and use it when I need to go back at the last article showed.
I don't know where i can store it, in the application.rb or in the
articles_controller.rb, and how store it!

Thanks
37fa021ceb617276328f0c6af1c3da81?d=identicon&s=25 Stefano Bortolotti (mex23)
on 2007-05-21 14:02
I tried this:
-in application.rb

  def current_article
  if @current_article
    return @current_article
  else @params[:id]
    return @current_article = @params[:id]
  end
  end

-in articles_controller.rb

  def show
    @article = Article.find(current_article)
  end

It works if i try <%= link_to 'show', :action => 'show', :id => article
%>
but if I try <%= link_to 'show', :action => 'show', :id =>
@current_article %>
it doesn't work.

What is wrong? thanks
This topic is locked and can not be replied to.