Reputation: 1374
I am facing trouble rendering a partial in Rails 4.2.1
. There are no errors in the Rails Server logs and also no output in the view. I have removed the as:
option and the result is still the same. Even if I hardcode the partial, the view does not display the information and the server logs show no errors.
app/views/registry_requests/_index.html.erb
<p><%= request.vehicle.make %></p>
app/views/users/_admin.html.erb
<!-- Columns -->
<div class="row">
<!-- Dashboard -->
<%= render 'admin_panel' %>
<!-- Body Content -->
...
<!-- Widgets -->
...
<%= render partial: "registry_requests/index", collection: @registry_requests, as: :request %>
...
<!-- Blog Feed -->
<div class="col-sm-6">
<div class="admin-widget">
<h1 class="widget">Recent Blog Posts</h1>
...
</div>
<a class="admin-widget-link" href="blog_create.html">Create Post</a>
</div>
<!-- Current Moderators -->
<div class="col-sm-6">
<div class="admin-widget">
<h1 class="widget">Current Moderators</h1>
....
</div>
<a class="admin-widget-link" href="#">Manage Moderators</a>
</div>
</div>
</div>
</div>
logs
Started GET "/users/6" for ::1 at 2015-08-18 12:35:30 -0400
Processing by UsersController#show as HTML
Parameters: {"id"=>"6"}
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT 1 [["id", 6]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 6]]
Rendered users/_admin_panel.html.erb (0.4ms)
Rendered registry_requests/_index.html.erb (0.0ms)
Rendered users/_admin.html.erb (3.8ms)
Rendered users/show.html.erb within layouts/application (5.8ms)
Completed 200 OK in 117ms (Views: 113.7ms | ActiveRecord: 0.2ms)
Upvotes: 1
Views: 47
Reputation: 777
Nice!
make sure @registry_requests
is defined in your UsersController#show
Upvotes: 2
Reputation: 1812
You should try doing something like this:
In your app/views/users/_admin.html.erb
<% @registry_requests.each do |request| %>
<%= render partial: "registry_requests/index", :locals => {:registry_request => request} %>
<% end %>
app/views/registry_requests/_index.html.erb
<p><%= registry_request.vehicle.make %></p>
Since @registry_requests
is a collection so you will have to iterate through it to get each record so that you can find each record's make
.
Upvotes: 0
Reputation: 310
Try this:
<% request.each do |one_request| %>
<p><%= one_request.vehicle.make %></p>
<% end %>
Upvotes: 0