Reputation: 1099
I have a search controller in which I get the client from params.
def show
@client = Client.find(params[:id])
@training_session = @client.training_sessions.new
end
In the form I am trying to pass the client_id value:
<%= form_for @training_session do |f| %>
<% binding.pry %>
<%= f.hidden_field :client_id, value: @client.id %>
But in training_sessions_controller params[:client_id] is nil.
private
def find_client
binding.pry
@client = Client.find(params[:client_id])
end
Why is the client_id parameter not passing from the form?
Upvotes: 0
Views: 91
Reputation: 1895
First take look to the HTML form generated by the view. However in your controller you should get your client id as:
training_session_params = params.require(:training_sessions).permit(:client_id)
client_id = training_session_params[:client_id]
Because the form is created for the TrainingSession model and not for the Client one.
Upvotes: 2