James McCarthy
2006-Mar-22 00:05 UTC
[Rails] How do I substitute variables into class names?
In a partial that renders another partial, I would like to change the items I am rendering based on the content of a variable. So instead of having 5 partials which all have variations on this; <% for @skill in @cv.skills %> <%= render :partial => "skills" %> <% end %> If item = "skill" would like to do something to this effect; <% eval("for @#{item} in @cv.#{item}s") %> <%= render :partial => "#{item}s", :local => {:item => "skill"} %> <% end %> But this does not work... anybody got any ideas? -- Posted via http://www.ruby-forum.com/.
Charles Leeds
2006-Apr-27 22:02 UTC
[Rails] Working around fields named for reserved words in legacy databases
I am running Rails 1.1.2. I am working with a Microsoft SQL Server database for a purchased application and it has a field named "Type", which is a reserved word in Ruby on Rails. Is there any way to customize my model so that I can use ActiveRecord.find on the table instead of having to use the "execute" method and manually write SQL code for everything? Changing the field name is unfortunately not possible. Thanks, Charles Leeds
Noel R. Morais
2006-May-30 05:15 UTC
[Rails] Working around fields named for reserved words in legacy databases
Charles, i have the same problem, did you solve this? Thanks, -- _________ Noel R. Morais On 4/27/06, Charles Leeds <charlesleeds@rowdyrhino.com> wrote:> I am running Rails 1.1.2. > > I am working with a Microsoft SQL Server database for a purchased > application and it has a field named "Type", which is a reserved word in > Ruby on Rails. Is there any way to customize my model so that I can use > ActiveRecord.find on the table instead of having to use the "execute" > method and manually write SQL code for everything? Changing the field > name is unfortunately not possible. > > Thanks, > > Charles Leeds > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Josh Susser
2006-May-30 06:36 UTC
[Rails] Re: Working around fields named for reserved words in legacy
Charles Leeds wrote:> I am working with a Microsoft SQL Server database for a purchased > application and it has a field named "Type", which is a reserved word in > Ruby on Rails. Is there any way to customize my model so that I can use > ActiveRecord.find on the table instead of having to use the "execute" > method and manually write SQL code for everything? Changing the field > name is unfortunately not possible.The field "type" is used for STI (Single Table Inheritance), but you can override it in your model class. http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000879 To change it to "flavor", put the following in your model class: def inheritance_column "flavor" end -- Josh Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.com/.