Rails: Different prices for different branches, association depending on two other models combined

Posted by Greg Lemond on Stack Overflow See other posts from Stack Overflow or by Greg Lemond
Published on 2012-06-09T16:31:10Z Indexed on 2012/06/09 16:40 UTC
Read the original article Hit count: 234

I have three models:

Service
has_many :prices
has_many :groups, through: prices

Price
belongs_to :service
belongs_to :group

Group
has_many :prices

I want to have an input field (Simple_Form) for every price. In views/services/_form.html.haml I do:

simple_form_for @service do |f|
    simple_fields_for :groups do |g|
        simple_fields_for :prices do |p|
            p.input :price

With this setup I only get input fields for already saved prices. How I can get a price field for every group? I tried to do it manually, but it got really nasty and didn't work either.

Thanks for any ideas!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about nested-forms