I have a model in rails called info
with address:string
and in my view I have the same input field that a user can enter a value into. Heres my form.html
<%= form_for(@info) do |f| %>
<%= f.text_field :address %>
<%= f.text_field :address %>
<% end %>
I know it sounds weird not to add another additional field in the info table, but I'm trying hard just to use address column alone. I'm trying to display both the values in the show but only the last one is displayed, my guess that the first address is not saved but the last one is always saved instead of both.
My show html
<p>
<strong>Addresses:</strong>
<%= @info.address %>
</p>
How can I save both values into the table from the two input fields and display them both in my show. html? If anyone can provide a way or a solution I would be thankful.
UPDATE
def create
address_array = params[:info][:address]
address_string = address_array[0] + ', ' + address_array[1]
params[:info][:address] = address_string
respond_to do |format|
if @info.save
format.html { redirect_to @info, notice: 'Info was successfully created.' }
format.json { render action: 'show', status: :created, info: @info }
else
format.html { render action: 'new' }
format.json { render json: @info.errors, status: :unprocessable_entity }
end
end
end