Я хочу вставить данные в две таблицы, если нажать кнопку. Пожалуйста, помогите мне.
counter_no.rb
class CounterNo < ApplicationRecord
belongs_to :queuelist, inverse_of: :counter_no
end
queuelist.rb
class queuelist < ApplicationRecord
acts_as_sequenced start_at: 000001
#belongs_to :member
belongs_to :user
has_many :counter_nos, inverse_of: :queuelist
end
queuelist_controller.rb
def make_queue
@queue = Queuelist.new.tap do |q|
q.dated = Time.now
q.member_id = current_member.id
q.user = User.find(params[:id])
q.build_counter_no(user_id: 1)
end
@queue.save
# respond_with(@queue)
redirect_to shops_url
end
def queue_params
params.require(:queuelist).permit( :id, :queuerule_id, :queue_number, :queue_status,
:dated, :phone_number, :ref_number, :sequential_id,
counter_no_attributes: [:id, :counter_no, :counter_dated, :startqueuetime, :closequeuetime,
:queuelist_id, :user_id, :member_id, :_destroy] )
end
queuelists> new.html.erb
<%= link_to "Call Action", { controller: "queuelists", action: "make_queue" }, id: @shop, class: "btn btn-info btn-lg top-space queue_btn" %>