Missing partial with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}

2.8k views Asked by At

I want to render a form in a show.

I know the error doesn't come from the path or a folder that I forget to create because the partial is not showing, not even in the application.html.erb file wherease the two other partial in shared folder are showing in application.html.erb

Here is my arboescence :


├── views
│   ├── contact
│   └── devise
    └── layout
    |         └── application.html.erb
    └── pages
    └── projects
    |
    |
    └──shared
    |        └── _contactform.html.erb  <----- IS NOT SHOWING, not even in application.html.erb
    |        └── _dropdown.html.erb     <----- is showing in: layout --> application.html.erb
    |        └── _flashes.html.erb      <----- is showing in: layout --> application.html.erb
    |        
    └──users
            └── index.html.erb
            └── show.html.erb    <----- contactform should be displayed here

Here is the code of the form

_contactform.html.erb:

<%= form_for @contact, url: contact_index_path, remote: true do |f| %>
    <div class="col-md-6">
        <%= f.label :name %></br>
        <%= f.text_field  :name, required: true, class: "contact-form-text-area" %></br>

        <%= f.label :email %></br>
        <%= f.text_field :email, required: true, class: "contact-form-text-area" %></br>

      <%= f.label :message %></br>
      <%= f.text_area :message, rows: 8, cols: 40, required: true, class: "contact-form-text-area",
                        placeholder: "Send me a message"%></br>

      <div class= "hidden">
        <%= f.label :nickname %>
        <%= f.text_field :nickname, :hint => 'Leave this field blank!' %>
      </div>

      <%= f.submit 'Send Message', class: 'btn btn-primary' %>
    </div>
  <% end %>
  <div class="col-md-6" id="flash-message">
  </div>

Here is the controller code

class ContactController < ApplicationController
  def index
    @contact = Contact.new(params[:home])
  end

  def create
    @contact = Contact.new(params[:home])
    @contact.request = request
    respond_to do |format|
      if @contact.deliver
        # re-initialize Contact object for cleared form
        @contact = Contact.new
        format.html { render 'index'}
        format.js   { flash.now[:success] = @message = "Thank you for your message. I'll get back to you soon!" }
      else
        format.html { render 'index' }
        format.js   { flash.now[:error] = @message = "Message did not send." }
      end
    end
  end
end

Here is the user_controller

class UsersController < ApplicationController
  skip_before_action :authenticate_user!, only: [ :index, :show ]

  def index
    @users = User.all
  end

  def show
    @user = User.find(params[:id])
  end

  def edit
    @user = User.find(params[:id])
  end

  def update
    @user = User.find(params[:id])
    @user.update(user_params)
    # Will raise ActiveModel::ForbiddenAttributesError
    redirect_to root_path(@user)
  end

  private

  def user_params
    params.require(:user).permit(:email, :first_name, :last_name, :description, :facebook, :instagram, :twitter, :linkedin, :phone_number, :country, :birth_date, :job_title, :id)
  end

end

My local host give me this error message :

Missing partial shared/_contactform with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}.

The partial _contactform.html.erb is in views --> shared . The other files in this shared folder are partials too and are working and rendering perfectly well ! This is what I don't understand the most .

I have tried to move the form file to an other folder and modifying the path when I call it on the show but this is still the same error message.

I would think there is an error in my path or something but the exact same error is show when I trie to read the partial in the application.html.erb as the two other partials in the shared folder.

1

There are 1 answers

1
Athira Kadampatta On

While rendering the partial inside users/show.html.erb, make sure to call it without the _ as follows:

<%= render 'shared/contactform' %> and NOT <%= render 'shared/_contactform' %>