Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Missing partial Ruby Chapter 8 tutorial

I am using Ruby on Rails Tutorial by Michael Hartl - Chapter 8 - Rails 3 I use rails 3.1 In the file new.html.erb I have:

<h1>Sign up</h1>
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages' %>

Trying to visit http://localhost:3000/signup, it gives me the following message:

ActionView::MissingTemplate in Users#new

Missing partial /shared/error_messages with {:handlers=>[:erb, :builder, :coffee], 
:formats=>[:html], :locale=>[:en, :en]}. Searched in:
* "/Users/macbook/rails_projects/sample_app/app/views"

I have googled around but could not find this answer. The same question was posted a while ago at: Ruby Chapter 8 tutorial partial file not found

What I tried: -putting a / in front of shared - putting :partial => after render -putting :target => @user

If I don't put it into the shared folder, it works. Is there a different way to do this in rails 3.1.3? Please let me know because I've spent so much time trying to figure it out.

like image 600
user1162885 Avatar asked Dec 01 '22 06:12

user1162885


2 Answers

If you say;

<%= render 'shared/error_messages' %>

it will look for a partial named shared/error_messages in the app/views/#{controller_name}

ie. if you're in the users#signup action, it will expect to find app/views/users/shared/error_messages

If in fact you mean app/views/shared/error_messages then you should say the following.

<%= render '/shared/error_messages' %>

That's just the only way to avoid ambiguity.

like image 114
Matthew Rudy Avatar answered Dec 28 '22 11:12

Matthew Rudy


Did you name the file correctly (with the underscore)? That was my problem...

error_messages.html.erb

should be

_error_messages.html.erb

like image 29
Nathan Crenshaw Avatar answered Dec 28 '22 09:12

Nathan Crenshaw