Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

Ricardo Castañeda's Profile

GitHub User: cadence96

Comments by Ricardo Castañeda

Avatar

In Rails 3.0.3 I get "undefined method `klass'" from the application_helper.

This is the syntax I'm using:

ruby
def link_to_add_fields(name, f, association)
    new_object = f.object.send(association).klass.new
    id = new_object.object_id
    fields = f.fields_for(association, new_object, :child_index => id) do |builder|
      render(association.to_s.singularize + "_fields", :f => builder)
    end
    
    link_to(name, '#', :class => "add_fields", :data => {:id => id, :fields => fields.gsub("\n", "")})
  end

Is my syntax correct? Does "klass" work with my rails version?

Thanks