This is the main idea:
controller
class ProductsController < ApplicationController
def index
@mode = params[:mode] || 'list'
respond_to do |format|
format.html
format.js
format.xml do
end
end
end
end
representation
<h1>Listing Products</h1>
<%= render params[:mode], :products => @products %>
<ul>
<% for p in products %>
<li><%= p.name %></li>
<% end %>
</ul>
<table>
<% for p in products %>
<tr>
<td><%= p.name %></td>
</tr>
<% end %>
</table>
Using:
, :
<%= link_to "View as list", products_path(:mode => "list") %>
<%= link_to "View as table", products_path(:mode => "table") %>
.. -, URL-.