Forum: Ruby on Rails Save the current article id

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Stefano B. (Guest)
on 2007-05-20 20: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.
Stephen B. (Guest)
on 2007-05-20 21:08
(Received via mailing list)

Depending on your code, you should be able to just do 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,

Stefano B. (Guest)
on 2007-05-20 21:26
I don't want to access to the current 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!

Stefano B. (Guest)
on 2007-05-21 16:02
I tried this:
-in application.rb

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

-in articles_controller.rb

  def show
    @article = Article.find(current_article)

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.