Title: How to use Rails select with ransack
Tags: ruby-on-rails;ruby-on-rails-3.2
Question: I need to use Rails select method as oppose to *text_field* to search for legacy data. Unfortunately, one of the attributes in the Project's table is capitalized, and even if I use alias_attribute on it, it still complains for correct naming from the actual table. The code blow works to a point, but instead of passing the Project_cont as the name value in the params, I get an id for that Description. How can I make this work? Here is the current code I have at the moment:
= search_form_for @search, :html =&gt; {:class =&gt; "form-inline"} do |f|
.form-group
= f.select :Decsription_cont, options_from_collection_for_select(Project.all, "id","Description", @search)
Here is the controller's code:
def index
@search = Project.search(params[:q])
@products = @search.result
end
Here is the view's code:
= search_form_for @search, :html => {:class => "form-inline"} do |f|
= f.select :Decsription_cont, options_from_collection_for_select(Project.all, "id","Description", @search.description_cont)
= f.submit


Here is another answer: You should add description_cont to your @search, like this:
f.select :description_cont, options_from_collection_for_select(Project.all, "id", "description", @search.description_cont)
Comment for this answer: And it's not just the typo: Decscription versus Description?
Comment for this answer: I suggest you add the relevant parts of the code in your view, controller and model to your question, so that we can have a look. Should be something "simple"...
Comment for this answer: Nicholas, if this is exactly the code as it is, it doesn't surprise me it doesn't work: in your select you're still talking about DeCSription, while in the same line you speak about DeSCription
Comment for this answer: naming is case sensitive! does that fix the issue?
Comment for this answer: Thanks @Danny. I am still getting an error saying 'it can not find Decsription_cont'. Not sure why, since the table contains Description attribute, and predicate is correct. I am thinking of actually doing something simpler then using ransack, i.e. write my own search method in the model and using it that way to search. If you have any other suggestions, I'd be interested to hear. Thanks again for help.
Comment for this answer: No, I've double checked for it like ten times :-) thinking I am going crazy and it still didn't work. Anyhow, I've written something simple that would do the same job, but pity this didn't work out.Again, if you have more suggestions I'll be happy to hear from you. Thanks again @Danny!
Comment for this answer: Sure, I've edited the initial posting above and added relevant code. Let me know if this is enough? Thanks @Danny.
Comment for this answer: You are right Danny. It was my typing into the editor above. However, even with correct naming, I am still getting error, for undefined method `description_cont' for #<Ransack...

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:02/06/14', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<ruby-on-rails><ruby-on-rails-3.2>', 'Title': 'How to use Rails select with ransack', 'ViewCount': 2026, 'id': 21592043, 'user_AboutMe': None, 'user_AccountId': 1274175.0, 'user_DisplayName': 'Nicholas Alek', 'user_Reputation': 263.0, 'user_Views': 46.0, 'user_id': 1695867.0}}