# Save the current article id

**URL:** <https://www.ruby-forum.com/t/save-the-current-article-id/104614>\
**Category:** Rails\
**Created:** [May 20, 2007, 6:36pm UTC](https://www.ruby-forum.com/t/save-the-current-article-id/104614 "2007-05-20T18:36:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mex23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@mex23](https://www.ruby-forum.com/u/mex23)\
**Post date:** [May 20, 2007, 6:36pm UTC](https://www.ruby-forum.com/t/save-the-current-article-id/104614/1 "2007-05-20T18:36:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mex23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@mex23](https://www.ruby-forum.com/u/mex23)\
**Post date:** [May 20, 2007, 7:26pm UTC](https://www.ruby-forum.com/t/save-the-current-article-id/104614/2 "2007-05-20T19:26:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mex23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@mex23](https://www.ruby-forum.com/u/mex23)\
**Post date:** [May 20, 2007, 7:08pm UTC](https://www.ruby-forum.com/t/save-the-current-article-id/104614/3 "2007-05-20T19:08:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mex23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@mex23](https://www.ruby-forum.com/u/mex23)\
**Post date:** [May 21, 2007, 2:02pm UTC](https://www.ruby-forum.com/t/save-the-current-article-id/104614/4 "2007-05-21T14:02:08Z")

</div>

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
