Ruby on Rails - Render form for model

when I render an partial for my model I'm using:

<%= partial @my_model %>

Automatically it looks for the file ..view/my_models/_my_model.html.erb I really like this notation because it feels the right way!

My Problem: Now I want a notation to automatically look up for the edit partial. Is there a way? Until now I used

<%= partial 'edit' %>

This is ok, but I have a lot of subclasses for my model and I liked the way that it automatically looks up in the right subclasses view folder for the template. Until know I have to look for the class for my model and then call

<% if @my_model.class == FirstSubClass %>
    <%= partial 'firstsubclasses/_edit.html.erb' %>
<% elsif @my_model.class == SecondSubClass %>
    <%= partial 'secondsubclasses/_edit.html.erb' %>
<% end %>

I prefer one line :) Any ideas?

Answers


Try:

<%= partial '#{@my_model.class.name.tableize}/_edit.html.erb' %>

tableize is a method of ActiveSupport::Inflector, which includes some other cool naming manipulation methods.


Need Your Help

Memory management for vertex buffer data

c++ direct3d vertex-buffer

Assume that I need to render static picture (100 stars).

After sending a search query page become blank

php mysql

I am working on a little search engine in PHP &amp; MySQL. Yesterday, I restyled (I did changes only at the HTML part, no php code was touched) the result page, after that I was unable to search fo...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.