Reputation: 831
I have this form:
= simple_form_for @post, validate: true do |f|
.edit-form
= f.input :title
= f.input :location
= f.input :price
= f.button :submit
The input form obviously is a blank text box that people put in their location.
I currently have Geocoder in my app and what I would like to do is pre-fill the location text box with the location of the user. Doing this requires this line of code:
= request.location.city
= request.location.state
I want to prefill this in my location text box. I tried doing something like this:
= f.input :location, value: (#{request.location.city}, #{request.location.state})
The end product should have the info filled in automatically and look like this:
This did not work. How do I insert it to accomplish this goal?
Upvotes: 0
Views: 316
Reputation: 448
The other answers are wrong. The correct way to do this is:
= f.input :location, input_html: { value: "#{request.location.city}, #{request.location.state}"}
It is necessary to include the
input_html: { }
If you want to add any additional HTML attributes.
Upvotes: 1
Reputation: 480
Instead of putting parenthesis around the value, use quotes to make it value: "#{request.location.city}, #{request.location.state}"
.
Upvotes: 0