Ruby RoR, Ransack, multiple select query fails - ruby-on-rails

using the ransack gem i've seen that it should be possible to use a form with multiple select.
using the basic html for the select form I use, and then select BOTH options to that I can attempt to search for either value
<select id="q_c_0_v_0_value" name="q[c][0][v][0][value][]" size="1" multiple="multiple">
<option value="SGD">SGD</option>
<option value="USD">USD</option>
</select>
and also tried
<select id="q_c_0_v_0_value" name="q[c][0][v][0][value]" size="1" multiple="multiple">
<option value="SGD">SGD</option>
<option value="USD">USD</option>
</select>
with combinations for all of the predicates "equal any", "contains any" etc,
I get resulting
SELECT "auctions".* FROM "my_table" WHERE (("auctions"."currency" LIKE '%["SGD", "USD"]%'))
and
SELECT "auctions".* FROM "my_table" WHERE ("auctions"."currency" LIKE '%USD')
Any ideas, the link https://github.com/ernie/ransack/issues/7 says its possible, but I dont seem to get the right results.

Related

How do I make product column width in Volusion span the entire screen for mobile and have products stack?

Trying to make product column width in Volusion span the entire screen for mobile and have products stack below. I am working out of this site: http://enpgp.fzsvf.servertrust.com/category-s/100.htm and you can see on mobile the products simple cram together as opposed to stacking.
You need to go to each category that you want to be responsive and select in the category display mode dropdown menu "Responsive Grid".
If that option for some reason is not shown you can force the category into "responsive mode" by changing one of the options in the "Product Display Mode" to "7" and then select it and click the save button. You would do that with Firebug. You could also import a "7" into "Product Display Mode" for that category via the API.
<select name="Category_DisplayMode" onblur="ProcessFieldUsage(this);" onkeyup="ShowSave()" onchange="ShowSave()">
<option value="">Select</option>
<option value="1">Single Rows</option>
<option value="2">Grid</option>
<option value="4">Checkboxes</option>
<option value="5">List</option>
<option value="6">Lightweight Grid</option>
</select>
Shown after the modification
<select name="Category_DisplayMode" onblur="ProcessFieldUsage(this);" onkeyup="ShowSave()" onchange="ShowSave()">
<option value="">Select</option>
<option value="1">Single Rows</option>
<option value="2">Grid</option>
<option value="4">Checkboxes</option>
<option value="5">List</option>
<option value="7">Lightweight Grid</option>
</select>

Mark prepopulated select options as selected in asp.net razor

I am trying to do select an option in a select element. I tried the following code. But it does not work.
<select>
<option value="1" #(ViewBag.dt.Rows[0][1].ToString())=="1"? selected>A</option>
<option value="2" #(ViewBag.dt.Rows[0][1].ToString())=="2"? selected>B</option>
<option value="3" #(ViewBag.dt.Rows[0][1].ToString())=="3"? selected>C</option>
</select>
Any help?
Thank you.
Your conditional operators appear incomplete (invalid code).
Did you mean:
<option value="1" #(ViewBag.dt.Rows[0][1].ToString() == "1" ? "selected" : "")>A</option>
I would normally suggest switching to #Html.RadioButtonFor but that will not handle a two-dimensional array references. Are you display multiple items in a loop? You may be able to simplify the whole thing (please show the rest of your page/code).

How do I select an option from a select box using Capybara in Rails 4?

I'm trying to select an option from a select box using Capybara and I've tried multiple combinations and ways to select the item but Capybara says it can't find the element. Here is the HTML that it is selecting from:
<select id="subject_id" name="subject[id]"><option value="">Select a subject</option>
<option value="25">Biology & Life Sciences</option>
<option value="26">Business & Management</option>
<option value="27">Chemistry</option>
<option value="28">Communication</option>
<option value="29">Computer Science</option>
</select>
I've tried multiple combinations such as these to select "Computer Science" which has a value of "29" from the list:
select "Computer Science", from: "subject_id"
find('subject_id').find(:xpath, 'option[29]').select_option
find('subject_id').find("option[value='29']").click
select "29", from: "subject[id]"
I know this doesn't have to do with being on the right page as I am logged in and I've run similar tests that require authentication but don't require the use of select boxes.
Those are just among the 9 or 10 different combinations I have tried so far. What is it that I am doing wrong and what can I do to stop getting this Capybara::ElementNotFound error?
To select <option value="29">Computer Science</option> option, you will need to select option as below:
select "29", from: "subject_id"
Pass the option value to select.
29 is the option value for option Computer Science.

How to convert multi select form field with GET tto have propper URL?

<select name="channel[]" multiple="multiple">
<option value="pants">Pants</option>
<option value="tshirts">T-Shirts</option>
<option value="sweats">Sweats</option>
</select>
So, form is GET, and if I select multiple, and when I click on submit URL is like:
?channel[]=pants&channel[]=tshirts
I need it to be like:
?channel=pants+tshirts
This cannot be achieved with an HTML only form. You'll have to incorporate javascript to manipulate the value of channel.

Freemarker hash for Struts2 #s.select tag's list property

I'm using Freemarker as the templating engine for a Struts 2 application and having some problems trying to pass a Freemarker hash to the #s.select tag's list value.
Currently I'm trying something like this in my template:
<#s.select name="myDropdown" list={"1":"Foo", "2":"Bar", 3:"Baz"} />
The resulting HTML that's rendered is this:
<select name="myDropdown" id="myDropdown">
<option value="freemarker.ext.beans.HashAdapter$1$1$1#2c9bebb">freemarker.ext.beans.HashAdapter$1$1$1#2c9bebb</option>
<option value="freemarker.ext.beans.HashAdapter$1$1$1#16ca4a">freemarker.ext.beans.HashAdapter$1$1$1#16ca4a</option>
<option value="freemarker.ext.beans.HashAdapter$1$1$1#173ee8">freemarker.ext.beans.HashAdapter$1$1$1#173ee8</option>
</select>
Based on the documentation it seems like this should work, but really the only examples are of using Freemarker lists. Hashes are only mentioned as another option, but I haven't been able to find any code examples that use them.
Ultimately my question is, what Freemarker syntax should I use with the Struts 2 select tag in order to render the following HTML?
<select name="myDropdown" id="myDropdown">
<option value="1">Foo</option>
<option value="2">Bar</option>
<option value="3">Baz</option>
</select>
Using the listKey and listValue properties of the select tag seems to do the trick.
The working code is now:
<#s.select name="myDropdown" list={"1":"Foo", "2":"Bar", 3:"Baz"} listKey="key" listValue="value" />
Seems like that should be taken care of automatically by the tag, but I was not able to get it to work without explicitly setting those two additional properties.

Resources