Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to fix params require for form_for contact in multi controller view

Anthony BESSON asked in Rails

I have a problem in my contact form_for, I have one contact form and I want to render my contact form in my product view. If I make that I have a problem with my require params

My contact_params work in my ContactController:

def contact_params
   params.require(:contact).permit(:name, :email, :body)
end

I have add in my ApplicationController

def set_contact
   @contact = Contact.new params[:contact] || {}
end

and that in my ProductsControler

show
   @contact = :set_contact
end

my route are:

get 'contact', to: 'contacts#new', as: 'new_contact'
post 'contact', to: 'contacts#create', as: 'create_contact'

my render is same that:

<%= render :partial => "contacts/contact" %>

and my view in _contact.html.erb:

 <%= form_for @contact, url: create_contact_url do |f| %>
  <%= f.text_field :name  %>
  <%= f.email_field :email %>
  <%= f.text_area :body  %>
 <%= f.submit 'Send' %>

Rails say me:

ActionController::ParameterMissing (param is missing or the value is empty: contact):

If I delete require(:contact) that not work rails say me:

Unpermitted parameter: :contact

Thanks

Reply

in ProductsControler

Change

show
   @contact = :set_contact
end

to

show
   @contact = set_contact
end

juste delete :

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,972+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.