Ask A Question

Notifications

You’re not receiving notifications from this thread.

Missing partial error even though lookup context comes back as true.

Matt Taylor asked in Rails

I'm getting a missing partial error even though my lookup context check comes back as true. My partials is in views/activity_feed/ and is named _appointment_set.html.erb

<% @activities.each do |activity| %>
                  <% if lookup_context.exists?(activity.action.parameterize.underscore, ["activity_feed"], true) %>
                  <%= render partial: 'activity_feed/#{activity.action.parameterize.underscore}', locals: {activity: activity} %>
                  <% end %>
                <% end %>

Here is my activity record

[#<Activity id: 1, user_id: 1, contact_id: 1, action: "Appointment Set", activitable_id: 4, activitable_type: "Appointment", created_at: "2017-02-05 02:58:17", updated_at: "2017-02-05 02:58:17">,

Anything jump out to anyone?

Thanks

Reply

I haven't used this before, so I'm just basing this off of pure observation, but are you sure your render partial is correct? Based on this => Render Tempalte if Exists in Rails their partial path is just the partial name, whereas yours is including activity_feed

So based on this idea, you could try:

<%= render partial: activity.action.parameterize.underscore, locals: {activity: activity} %>
Reply

Oh Jacob. You are a life saver. So if i put the partials in the same folder as show page and render it like you have above it works. I have to adjust the lookup context to the right folder but it works... It just seems weird that the lookup would do it start at the view folder level and work from there but the partial is starting from the parent folder of the file your in.

I'm trying to use these partials for more than one controller. There has to be a way to have the render partial look outside parent folder for partial right? I was pretty sure you could just add the path from the view folder to where the partial was, but obviously i'm missing something here.

Thanks again for the help.

Reply

Oh sweet, I'm glad that got the gears turning again!

This reminds me, awhile back on another project I had to be explicit when giving the partial name from the controller, I wonder if this may be similar in your case? May be worth looking into...

In my controller, I had to do this to get it to render, otherwise I'd get the missing partial error:

respond_to do |format|
  format.js { render 'shared/_toggle_alert.js.erb' }
end

This was to toggle an alert box that could pop-up on any given page. I never did figure out the real reason why it had to be written as such, I just know no other method worked. Still curious as to why I had to include the underscore and extension...

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,733+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.