I am trying to submit 2 values to a rails scope. I need the radius (submitted by a range tag) and the postcode.
I have a fields_for tag in a form (in haml):
=f.fields_for :postcode do |postcode_fields|
=postcode_fields.text_field(:postcode_d,placeholder: "HQ Location")
=postcode_fields.range_field(:max_range, in: 1..100)
Scope:
scope :postcode, lambda {|input|
return nil if input.blank?
terms = Scotland.near(input[0], input[1])
where(
terms.map { |term|
" charity_id = ?"
}.join(' OR '),
*terms.map {|e|(e.charity_id)}.flatten
)
}
Controller:
def scotland_params
params.require(:scotland).permit!(:charity_number, :charity_name, :registered_date, :known_as, :charity_status, postcode: [:postcode_d,:max_range] , :constitutional_form)
end
The problem seems to be in my definition of postcode. I have tried a variety of ways to define the postcode hash, none of which have worked. For the one i have use here the error is
SyntaxError
(/Users/peterkentish/Documents/UNIVERSITY/SecondYear/Semester2/SoftwareHut/project/app/controllers/scotlands_controller.rb:46: syntax error, unexpected =>
..., :charity_status, postcode: =>[:postcode_d, :max_range] , :...
... ^
/Users/peterkentish/Documents/UNIVERSITY/SecondYear/Semester2/SoftwareHut/project/app/controllers/scotlands_controller.rb:46: syntax error, unexpected ',', expecting keyword_end
...: =>[:postcode_d, :max_range] , :constitutional_form, :previ...
... ^):
TL;DR How do i pass nested attributes in rails 5?
EDIT:
params hash (i think):
@scotlands = Scotland.all
@filterrific = initialize_filterrific(Scotland, params[:filterrific]) or return
@scotlands = @filterrific.find.page(params[:scotlands])
@scotlands = @scotlands.paginate(page: params[:page], per_page: 20)
respond_to do |format|
format.html
format.js
If anyone comes across this, there is a bug in the gem filterrific:
https://github.com/jhund/filterrific/pull/116
Thanks to those who helped