I have a form:
<%= form_for(:user_email, :url => {:action => 'send_email'}) do |f| %>
<%= f.text_field(:subject, class: 'form-control')%>
<%= f.button "Submit", type: 'submit'%>
<% end %>
And a controller:
class UserEmailController < ApplicationController
def send_email
p params[:subject]
end
end
This writes nil
in the console instead of the text I put in my textfield.
Question: How can I access the content of my fields in the controller?
I should mention that the action itself is triggered, but the parameters are nil.
Use form_tag with your path. I have used /user_email/send_email
. change it according to the route your have setup in routes.rb
<%= form_tag('/user_email/send_email') do %>
<%= text_field_tag(:subject, class: 'form-control')%>
<%= submit_tag "Submit"%>
<% end %>
Try instead:
p params[:user_email][:subject]
And if that doesn't produce what you're looking for, try:
p params
... to inspect what's getting sent over the wire.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.