Is it safe/acceptable to send params this way to create action in the controller? Is there any potential problems?
<%= link_to "Acceptance", acceptances_path(acceptance: {favor_id: @favor.id, user_id: current_user.id}), method: :post %>
and then in controller
class AcceptancesController < ApplicationController
def create
@acceptance = Acceptance.new(acceptance_params)
if @acceptance.save
redirect_to favors_path
else
render :template => 'favors/index'
end
end
private
def acceptance_params
params.require(:acceptance).permit(:favor_id, :user_id)
end
end
Thanks for your time in advance!
belongs_to :userand alsobelongs_to :favor. Is it still acceptable to pass params with link_to when there is an association? or there is a better way of setting the attributes in the controller?.merge(favor_id: @favor.id, user_id: current_user.id)to your permited params. But I don't suggest you set it in view.