RailsCasts Pro episodes are now free!

Learn more or hide this

Chew Manfoo's Profile

GitHub User: chewmanfoo

Comments by Chew Manfoo

Avatar

Alan - the issue was in the product_types_controller, but your solution is in the products_controller. There might also be a problem in the products_controller, but initially, since product_types contains the :fields_attributes hash, the solution needs to be in permitting params[:product[:fields_attributes]] or somesuch. I notice the solution link you gave from stack makes the same mistake. Or, is it a mistake?

Avatar

Thanks Ryan for another excellent Railscast. I have seen several screencasts on the subject of search, and all of them limit the 'domain' of the search to just one 'entity'. This screencast searches Products. I need a search that finds anything on the, whether it be Products, or BlogPosts, or Orders or whatever. I can imagine one way to accomplish this - simply duplicate the effort here for Products, adding Orders alongside it, and then in the search results present a section for Products Found and another section for Orders Found. But isn't there a better way to accomplish this?

Avatar

anyone know what formtastic needs in the form to replace the collection_select for the first example (using Chosen). I have this:

f.input :change_set_revisions, :as => :select, :collection => ChangeSetRevision.all.sort_by(&:name).reverse

but it sticks with the normal multiple-select drop-down box. I do not get the javascript decoration.

Avatar

I was able to get grandchildren to work in the forms with a special application helper function:

ruby
  def special_button_to_add_fields(name, f, association, child_association)
    new_object = f.object.class.reflect_on_association(association).klass.new
    child_object = f.object.class.reflect_on_association(association).klass.reflect_on_association(child_association).klass.new
    new_object.wireless_client = child_object

    fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
      render(association.to_s.singularize + "_fields", :f => builder)
    end
    button_to_function(name, h("add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")"))
  end

Essentially, you have to create the grandchildren in this helper to have an object for the fields_for to attach to.