1
votes

I am trying to render html from app/views/companies/new.html.erb on one of my pages, but I get the error:

Missing partial companies/_new.html.erb with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :arb, :haml, :jbuilder]}. Searched in: * "D:/Documents/Code/pandora/app/views" * "D:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bootstrap-sass-extras-0.0.6/app/views" * "D:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/bundler/gems/active_admin-d44c1b8a57cc/app/views" * "D:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/kaminari-0.16.3/app/views" * "D:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/bundler/gems/devise-b12658782ff4/app/views"

This is what I have to render in my html.erb file that I am trying to load when I get this error: <%= render "companies/new.html.erb" %>

What could be causing this and how could I fix it.

Thank you.

1
In a view render will only look for partials, so it's looking for a file called _new.html.erb. What exactly are you trying to do? If this is on the create action in the controller you can do render :new which will tell the controller to render the files for the new action. - j-dexx
What I am trying to do I load/render the html from new.html.erb into another html file, so that I do not have to copy paste the whole thing and so that when I make changes to the file I do not need to go into every file that uses it and change it there also. - Pabi

1 Answers

2
votes

When you do <%= render "companies/new.html.erb" %>, it will look for _new.html.erb(a partial file). Try using the below code to render new.html.erb

<%= render template: "companies/new.html.erb" %>

Also, check render for more info.