This is my controller:
class RegularController < ApplicationController
before_filter :find_student
def regular_student
session[:page] = 'regular_student'
end
def generate_regular_student
@regular = RegularStudent.new()
@regular.codtitulo = params[:academic_title_id]
render :template => 'regular/_regular_student_output'
end
end
This are the important routes for this issue:
get '/regular_student' => 'regular#regular_student'
post '/generate_regular_student' => 'regular#generate_regular_student'
This is my regular_student.html.rb
form:
<%= form_for :generate_regular_student, url: "generate_regular_student" do |f| %>
<%= f.collection_select :id, @student.academic_titles, :academid_title_id, :name, {}, {class: "form-control
screen-only"} %>
<%= f.submit "Generar constancia", {class: 'btn btn-default'} %>
<% end %>
This is my partial _regular_student_output.html.erb
, in which I want to show the academic_title_id
which came as a param to @regular.codtitulo
, to make sure that I´m getting it correctly:
<h1>Generated!</h1>
<h2>Title: <%= @regular.codtitulo %></h2>
The problem is that the param never reaches the controller. When I push the submit button in the form, the terminal outputs the following:
Started POST "/generate_regular_student" for 172.16.2.67 at 2022-04-26 09:00:44 -0300
Processing by RegularController#generate_regular_student as HTML
Parameters: {"utf8"=>"✓","authenticity_token"=>"QjHc7k7NXlYgL1XlTiy6rYGgSvID 5II YusNm7n i3XT6vNwUzLUxmjG6aTEqAQP6zIKNsetAKpg2L3Qip4AA==", "generate_regular_student"=>{"academic_title_id"=>"221"}, "commit"=>"Generar constancia"}
So the param is generating correctly, but for some reason never reaches the controller. When I use @regular.codtitulo
in _regular_student_output.html.erb
I just get a blank <h2> </h2>
.
CodePudding user response:
As dbugger commented, the parameter reached the controller. My mistake was when using it. Instead of using:
params[:academic_title_id]
I should have used:
params[:generate_regular_student][:academic_title_id]
Credits to dbugger. Thank you very much!