I am trying to write a simple and generic one table maintenance shared
partial which can be reused to maintain multiple tables with the
following fields:
id, name, created_by, updated_by.
I am stuck in generating rest route correctly. Here is an example for a
“crust_types” table inspired by Ryan B. Forms screencasts.
Here is the index action from CrustTypeController:
def index
@crust_types = CrustType.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @crust_types }
end
end
Here is the content of corresponding index.html.erb template:
<%= render :partial => ‘shared/crud_table’, :object => @crust_types,
:locals => {:ll => ‘crust_type’} %>
Finally, here are the relevant code snippets from _crud_table.html.erb
partial in the shared folder:
<% for a_rec in crud_table %>
<tr class="<%= cycle(“odd”,“even”) %>">
"edit#{ll}_path(#{ll})” %> | <%= link_to ‘Destroy’, “#{ll}_path” ,
:confirm => ‘Are you sure?’, :method => :delete %>
<% end %>
The rest paths for link_to methods are not being evaluated they are
literally output. For example: I want the link_to ‘Edit’,
“edit_#{ll}_path(#{ll})” method to generate the correct edit path as
'/crust_types/1/edit for the first record, instead, I get
‘/edit_crust_type_path(crust_type)’. Clearly, it is not being
evaluated. How should I do it?
Thanks in advance for your time.
Bharat