0

I have the following models and relations:

Rate fields
  t.string :type
  t.string :name

class Rate < ActiveRecord::Base
  has_many :category_rate_requests
end

CategoryRateRequests fields
  t.date :date_from
  t.date :date_to

class CategoryRateRequests < ActiveRecord::Base
  belongs_to :rate
  has_many :category_rates
end

CategoryRate 
  t.integer :room_category_id
  t.integer :new_rate_id
  t.integer :category_rate_request_id
  t.integer :amount

class CategoryRate < ActiveRecord::Base
  belongs_to :rate
  belongs_to :category_rate_request
  belongs_to :room_category
end

And I'm trying to have a nested_form inside a nested_form

= nested_form_for @rate do |f|
  = label_tag :name, t('rates.new.name'), class: 'grey h2'
  = f.text_field(:name, required: true, class: 'form-input form-control full-width-input')
  = f.fields_for :category_rate_request do |request|
    = request.text_field(:date_from,  class: 'date-input form-control start-date-input', type: 'text', 'data-provide': 'datepicker', placeholder: t('common.date_from'))
    = request.text_field(:date_to, class: 'date-input form-control end-date-input', type: 'text', 'data-provide': 'datepicker', placeholder: t('common.date_to'))
    = request.fields_for :category_rate, do |u|
      = u.number_field(:price, class: "form-control", placeholder:  placeholder)

Overall this is the format. It has more things, but to not include too much unnecesary information I omitted some fields of the form.

But I get the following error

Completed 500 Internal Server Error in 690ms (ActiveRecord: 6.1ms)

SyntaxError - syntax error, unexpected keyword_do_block ; _slim_controls2 = request.fields_for :new_category_rate, do |u|; ^ /project/app/views/new_rates/_category_rate_requests.html.slim:61: syntax error, unexpected keyword_ensure, expecting end-of-input:

That line marked in red is:

= request.fields_for :new_category_rate, do |u|

Is there any way I can have the attributes of all three models in one form? In the Rate form more precisely.

5
  • Not enough code. Please post your parameters method for model A (should be something like def model_params where model is the name of your model. Commented Aug 16, 2016 at 14:26
  • Please provide snippet of the code and the error log. Commented Aug 16, 2016 at 14:35
  • 2
    You have an extra comma in the erroring line. Change it to: = request.fields_for :new_category_rate do |u| Commented Aug 16, 2016 at 16:23
  • Thank you, this was it. Can u put in an answer so that I can mark this as resolved? Commented Aug 16, 2016 at 17:51
  • Sorry for the late response. I've now made it an answer. Commented Aug 28, 2016 at 21:56

2 Answers 2

0

(copied from comment)

You have an extra comma in the erroring line. Change it to:

= request.fields_for :new_category_rate do |u|
Sign up to request clarification or add additional context in comments.

Comments

0

I don't know if you need to use that gem for a particular reason, but I think it hasn't been updated for too long for use it.

I use Cocoon, and with simple form you just need to do:

simple_form_for @a do |f|
  f.simple_fields_for :b do |b_f|
    b_f.simple_fields_for :c do |c_f|
      ...
    end
  end
end

You can use link_to_add_association and link_to_remove_association in a very friendly way too.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.