Anthony BESSON

Joined

750 Experience
0 Lessons Completed
1 Question Solved

Activity

in ProductsControler

Change

show
   @contact = :set_contact
end

to

show
   @contact = set_contact
end

juste delete :

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

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

© 2024 GoRails, LLC. All rights reserved.