Coder Social home page Coder Social logo

Comments (9)

carloslopes avatar carloslopes commented on June 26, 2024

I think you misunderstood the usage of control_group. It isn't an alternative to fields_for neither similar to it.

Here is an explanation of what is control_group for Bootstrap.

I'll close this issue now but if you have any other doubt ask me!

from bootstrap_form.

carlosdavis avatar carlosdavis commented on June 26, 2024

I'm sorry: I didn't provide enough specificity in my issue report. I'm not calling control_group directly. control_group gets called via FORM_HELPERS.each{|m| define_method etc.}:
https://github.com/potenza/bootstrap_form/blob/master/lib/bootstrap_form/form_builder.rb#L24

When that chain of methods executes on a key/value pair within a serialized hash (via fields_for), your code for object.errors throws an exception because that serialized hash item does not respond to .errors (especially if that item is nil).

from bootstrap_form.

carlosdavis avatar carlosdavis commented on June 26, 2024

Let me know if you need a stack trace or full example code.

from bootstrap_form.

carloslopes avatar carloslopes commented on June 26, 2024

Hm yes, it would be nice if you create a gist with a stack trace and an example code πŸ˜‰

from bootstrap_form.

carlosdavis avatar carlosdavis commented on June 26, 2024

https://gist.github.com/carlosdavis/6540470

from bootstrap_form.

potenza avatar potenza commented on June 26, 2024

Thanks. I'm taking a look at this now. I believe it may have been fixed in the 1.0 release, but I want to verify (from the stack trace, I see you're using 0.3.2).

from bootstrap_form.

carlosdavis avatar carlosdavis commented on June 26, 2024

Ah, thank you so much. We're on Rails 3β€”is the 1.0 release only for Rails 4?

from bootstrap_form.

potenza avatar potenza commented on June 26, 2024

You should be fine on 1.0 (I should note this in the README). In Rails 4, sending a block to FormBuilder.new is deprecated. To handle this, we just default the block to nil:

https://github.com/potenza/bootstrap_form/blob/master/lib/bootstrap_form/form_builder.rb#L10

I also created a Rails 3 test project with bootstrap_form 0.3.2 and was able to reproduce the error. Upgrading to 1.0 fixed it.

FYI, I had to explicitly set the text_field values to pull them from the preferences hash:

<%= bootstrap_form_for @user do |f| %>
  <%= f.text_field :email %>
  <%= f.fields_for :preferences do |builder| %>
    <%= builder.text_field :favorite_color, value: @user.preferences[:favorite_color] %>
    <%= builder.text_field :favorite_animal, value: @user.preferences[:favorite_animal] %>
  <% end %>
<% end %>

If you know the keys in advance, it might be simpler to define getters/setters for the preferences keys and skip fields_for altogether.

from bootstrap_form.

potenza avatar potenza commented on June 26, 2024

I'm gonna close this for now, but let me know if you're still having issues. Thanks!

from bootstrap_form.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.