Display us states dropdown on view in rails - ruby-on-rails

I have implement a helper which contains list of US states. Please check here:
Rails Select Drop Down for States?
Now I have to display the selected US state name on the view file. How can I access that?
As long as it is a drop-down it is working fine.
For example my user selected Maryland ,in the database the value inserted is MD.
Now,I have to display Maryland on the view page.
Please note I have simply created a helper named us_states in ApplicationHelper.

May be:
us_states.select{|v| v[1]=="WA"}.first[0]

Related

Rails admin cascading dropdown how to?

As you see in image below after selection of product attribute i want to filter the options based on the selected attribute_id
this is in rails_admin
I'm sorry to say there's no builtin way to do this.
You'll have to clone the existing belongs to field.
Check out the field implementation
https://github.com/sferik/rails_admin/blob/master/lib/rails_admin/config/fields/types/belongs_to_association.rb
And its view
https://github.com/sferik/rails_admin/blob/master/app/views/rails_admin/main/_form_filtering_select.html.haml
You'll find more details on how to create your own custom field here
https://github.com/sferik/rails_admin/wiki/Custom-field

RAILS 4 Dynamic generating of select tag

I have two select tags/controls and I need the second select tag options to be dynamically generate based on the selection of first
For example I want to make after selecting a car brand in first select, the second must show the models of selected car brand, But I have not been able to do it please help
Please watch rails cast #88 dynamic select menus revised. The method you need to do this called grouped_collection_select
This method along with the proper coffee script (or JavaScript if you prefer that more than coffeescript) discussed in the video will complete exactly what you're looking for

How do I get Grails g:select with multiple-selection with all selections when returning from the controller

I have a page that is a report from a database and I'm working on modifying how the filtering works. The intention is to allow the user to select possible values form a list that will be used to filter the resulting report. There are too many values to do this with checkboxes. I'm defining a multiple selection list box with this:
<g:select name="country" from="${countryDataList.KOUNTRY}" value="${params.country}" multiple="true" />
countryDataList is a List<> of objects with a name and a value which I create in the controller. I'm able to get the selected counties and process them without an issue.
But when the page returns from the controller with the filtered report, only the first selection in the list is selected. It doesn't re-select all of the items that the user selected. I am passing the params.country object back from the controller as
country:params.country
I saw some posts about this not working, but they are all from several years ago. Am I missing a vital step?
Ahh sorry, I was reading it on the phone initially and missed the point.
So what you want is a way of sending a multiple select box to a confirmation page. If I understand correctly?
Anyways how many objects in the select are we talking massive or a dozen couple of dozen or so ?
What I did was use check boxes and did a confirmation which shows the selection ticked in check boxes.. So this is the confirmation page that loads in https://github.com/vahidhedayati/mailinglist/blob/master/grails-app/views/mailingListEmail/confirmcontact.gsp
this page which is where multiple attachments selected from the schedule re-appear...
https://github.com/vahidhedayati/mailinglist/blob/master/grails-app/views/mailingListAttachments/_mailerAttachmentsDisplay.gsp.
Please note advice below is all conceptual stuff and there may be easier ways than this
Other than that You could create a taglib call on the confirmation page https://github.com/vahidhedayati/ajaxdependancyselection/blob/master/grails-app/taglib/ajaxdependancyselection/AutoCompleteTagLib.groovy#L55 which takes in your arrayList you could probably convert it to JSON pass it into the javascript that you load in within the taglib (on mine further down it loads this page in)
https://github.com/vahidhedayati/ajaxdependancyselection/blob/master/grails-app/views/autoComplete/_selectJs1.gsp#L23
and look to reselect them using javascript... as I say I haven't tested the last bit, the first bit i.e. checkbox works it is/has been in use.
Years later from you I just had the same problem. What I figured out is: it happens when params.country is an array instead of a Collection (i.e. an ArrayList).
A workaround for this if you want to stick to the array type is at the value attribute of the tag doing this: params.country?.findAll().

Rails: many-to-one display on form via dynamically added input text boxes

I have a form in rails that allows the user to create a new object (call it a search).
This object has_many excluded_phrases.
What I would like is the ability to display one text box per excluded phrase added.
The form will start out with only a single text box, allowing the user to add one excluded phrase. If they want to add more, there will be button labeled "+" that will dynamically add one more text box, and allow the user to add as many more items as he wants.
On form submit, this should populate the db with the user search, and create all the required phrases that are linked to that user search.
Help?
All inspiration needed is there:
http://railscasts.com/episodes/197-nested-model-form-part-2
This popular rails plugin does exactly what you want.

Make collection_select display as an image (Rails 3 App)

All,
BACKGROUND: I have a collection_select statement that displays a dropdown box.
OBJECTIVE: I'd like the dropdown to be an image that the user clicks to see the collection rather than the default box + down arrow that appears.
You need something like this plugin for jQuery. It allows you to replace a normal select with a custom one based on your wants. You would have to write your own select helper since you need to add the attributes to the select options that this plugin requires. If you get started and need help, post back here with what you're stuck on.

Resources