Topic: Cleaning my views
I am currently trying to clean up my views. As you can see in the last
example below, I'm having a new link to create a new resource
dynamically. The controller is given by the params[:controller]. This
way I create new action paths to all my resources with the same code.
I want now a similar thing but for the show action. The thing is that
I'll need the instance variable. How can I set the instance variable
dynamically for a show action. I'll have to add to the url_for method
below the 'show' parameter with the instance variable that comes from
the controller (example: @user, @message, @foo).
I tried the following first, but it didn't worked since the id is then
processed as a string "@user", so I get the following url: /users/
@user. I hope you guys can help me trying to solve this one. Thanks!
url_for(:controller => params[:controller], :action => "show", :id => "@"+params[:controller].singularize)
<div> <% link_to url_for(:controller => params[:controller], :action => "new") do %> <%= image_tag("add.png") %> <span><%= t('toolbar.new') %></span> <% end %> </div>