ruby on rails - Using form_for to create select tag with data being pulled from database -


i've been trying create select tag create dropdown menu list down items city database. able had hard code html form tag.

<form>     <%= select_tag :city, options_from_collection_for_select(city.all, :id, :city_name), class: "form-control" %> </form> 

now i'm trying convert code place in form_for tag, keep getting error: "undefined method `city_id'" f.collection_select line.

<%= form_for @city |f| %>    <div class="form-group">       <%= f.label :city_id, "city list" %>       <%= f.collection_select :city_id, city.all, :id, :city_name %>    </div> <% end %> 

i tried removing :city_id, "wrong number of arguments (3 4..6)", replaced :city_id nil , same undefined method error.

i new rails appreciated!

the form_for helper wraps object (in case, @city) , creates form fields fill in attributes, directly. so, based on error message, sounds @city not respond :city_id. in other words, @city.city_id give same error. need figure out attribute intending fill in here.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -