Answer the question
In order to leave comments, you need to log in
How to separate two params attributes in rails?
I am doing a range filter on the advice of the community, I ran into a search problem, namely, I don’t understand how to split the params into 2
form attributes
<%= form_tag @sub_category, method: 'get' do |d| %>
<%= text_field_tag "diameter[]", nil, id: "ex2", :data => {'slider-min' => '1','slider-max' => '1000','slider-step' => '5','slider-value' => '[250,450]' } %>
<%= submit_tag 'Save' %>
<% end %>
def show
@sub_category = SubCategory.friendly.find(params[:id])
@items = @sub_category.items
@items = @sub_category.items.where("size >= ?", params[:diameter].first) if params[:diameter].present?
@items = @sub_category.items.where("size <= ?", params[:diameter].last) if params[:diameter].present?
@items = @items
end
Answer the question
In order to leave comments, you need to log in
I don’t know what problem you are solving, why do you need a range, what the community advised ...
But if you need to "diameter"=>["21,451"]
make 21 and 451 out of it, then:
vals = params[:diameter].first.split(',') # [21,451]
val1 = vals.first # 21
val2 = vals.last # 451
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question