In #eyecolor contain hash
{"Brown"=>"Brown", "Black"=>"Black", "Blue"=>"Blue", "Green"=>"Green"}.
Now i want to show multiple check box in rails, and i have implement this code for this
<%= check_boxes_tag "eyecolor[]", options_for_select(#eyecolor, params['eyecolor']),{:multiple => true,:size=>5} %>
and i want to check Black
but it didn't show me multiple checkbox, It display me only one check box.
Related
I have a multiple select box in a form
<%= f.select :receipts, [], {}, multiple: true -%>
I want to ALWAYS post all options that are in the select box, but HTML only posts the ones the user has clicked on.
I could handle the submit event in JavaScript and set all the options to be selected, but I don't really want the user to see the items get selected. The form may fail to post and I'd prefer not to change anything visual on the screen.
The other thought I had was to use a hidden element and set its value to be a comma separated list of items from the multi-select box just before the submit happens. Then I don't have to mess with the selection state of the multi-select box.
Is there some Rails magic I can use instead of doing this?
I'm on mobile so don't have access to my code until later. But the basics are this: I have a simple_form to create/edit a listing on my site. Certain parameters are required. I use validates presence of in the model. When submitting the form, if I text box that is required isn't filled out, the validation works fine, error pops up and says please fill in. When a button is not selected for one of the collection selects, nothing happens. Obviously the validation is working because the form won't submit, but no error is thrown. Any ideas on how to get the error to show for a collection select with radio buttons?
In your form do you have?
<%= form.error_notification %>
Or you can do it in a different way, if you don't want to do it with the form helper.
<%= #instance_variable.errors.full_messages if #instance_variable.errors.any? %>
You can read more here.
I am designing a search page in Rails using Ransack and I need some help with check boxes.
I have several check boxes. Here is one of them.
<%= f.check_box :if_bt_eq %>BT
I know that when a check box is ticked it returns 1 and 0 when not ticked.
Is there any way in which I can change the non-ticked return value to nil ?
If not, can you suggest some sort of alternative for this?
Thanks!
Update:
Here's the hashes that are passed when the search form submit button is clicked:
with the check box ticked:
...q%5Bif_bt_eq%5D=1&...
with the check box not ticked:
...q%5Bif_bt_eq%5D=0&...
I want the check box not ticked to be
...q%5Bif_bt_eq%5D=&...
I knew that Rails3 no longer supporting link_to_remote.... instead of that we can modify
the link_to method by using different syntax as follows :
link_to "Send",{:action =>"send_mail",:question_id =>question.id},:remote => true,:class =>"button small"
My problem is, in my view i keep the select box which contains the list of user's name near by send link button (which user the above syntax)... i want to pass the selection box value to link_to when user click the send button
Here is my View code :
"send_mail",:question_id =>question.id,:user_value
=>encodeURIComponent($F('user_id'))},:remote => true,:class =>"button small" %>
I don't know how to achieve this ....can any one please suggest me on this.
edit: ok now is see your last comment... never mind
What I got from the question, you are looking for something like this:
http://marcgrabanski.com/articles/jquery-select-list-values
It's not really a Rails problem since you can't change the Ruby code from within the rendered HTML (at least that would be very risky if it's possible). The code from above can be easily changed to your needs so that the user gets redirected to the URL that matches the button value.
Ok, I think this is probably an easy question but for the life of my I can't figure it out. I have created a table called ugtags and in that table I have two columns (beyond the basics), 'name' and 'link'.
I am trying to allow a user to add a link to a page. Ideally they would enter the link title (name) and the url (link) and in the view it would display the title as a link to the url that was entered in the link column.
I there a way to do it by simply affecting the <%= link_to h(ugtag.name) %> code?
You should just be able to do:
<%= link_to h(ugtag.name), ugtag.link %>
See the documentation for all of the relevant options.