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.
on 2007-05-20 20:36
on 2007-05-20 21:08
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
on 2007-05-20 21: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
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] 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