I have a subscriptions form where I am trying to set the plan the user has chosen, the business they would like to associate with the subscription and the payment details. In my form I use a select tag to display a list of all of the businesses and it displays properly in my view but upon save I get the following error:
undefined method `map' for #<Business:0x007f8ea7955b90>
new.html.erb
<div class="field">
<%= select_tag :business_id, options_from_collection_for_select(@businesses, "id", "name") %>
</div>
subscriptions_controller.rb
...
def new
@subscription = Subscription.new
@plan = Plan.find(params["plan_id"])
@businesses = Business.all
end
def create
@subscription = Subscription.new(subscription_params)
raise "Please, check subscription errors" unless @subscription.valid?
@subscription.process_payment
@subscription.save
redirect_to @subscription, notice: 'Subscription was successfully created.'
rescue => e
flash[:error] = e.message
render :new
end
private
def set_subscription
@subscription = Subscription.find(params[:id])
end
def subscription_params
params.require(:subscription).permit(:plan_id, :business_id, :card_token, :coupon)
end
Am I setting up the select_tag properly? Do I need to fix my create method? Looked at other solutions on SO with little success.