I have really tough time with dropdowns in one sequence of project. Hence, I have two models
User.rb
class User < ApplicationRecord
has_many :addresses
end
and Address.rb
class Address < ApplicationRecord
belongs_to :user
end
Then I have checkout process-step one where user inputs his address. There are dropdown menu which should look like this:
Option 1: #{current_user.first_name} {current_user.last_name}, {current_user.address}
If User clicks on this option in dropdown menu(default) and then continue Address should be taken from current user and proceed.(this action is authorized)
Option 2: New Address
If User clicks on that option, new form should appear where User can input first_name, last_name and address.
I tried with select and collection select tags but seems it isn't what I need. I know that I can use onChange js method for form, but I don't know how to insert address on Option 1 as a valid argument for my form.
Any suggestions?
UPDATE
<%= form.fields_for :address do |form| %>
<%= form.select_tag "bill address", options_for_select([[Address.where(:user_id => current_spree_user.id).collect{|b| "#{b.firstname} #{b.lastname}: # {b.address1}, #{b.state}"}, current_user.id], ["New Adress", ""]] %>
<% end %>
I tried with this but got an error Couldn't find Address with 'id'=Nella Nienow: 801 Greenfelder Court, New York(I assigned this address to current_user in console)