Hugs
Hugs

Reputation: 935

Partial not being found Rails

I am following Michael Hartl's book to put in some following functionality into my app and when I attempt to use the AJAX on my follow and unfollow buttons I am receiving these errors when trying to change the buttons that are rendered:

Completed 500 Internal Server Error in 81ms

ActionView::MissingTemplate (Missing template users/follow_user, application/follow_user with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee]}. Searched in:
  * "/Users/hugo/Web Development/Rails/sample/app/views"
  * "/Users/hugo/.rvm/gems/ruby-1.9.2-p318/gems/kaminari-0.13.0/app/views"
  * "/Users/hugo/.rvm/gems/ruby-1.9.2-p318/gems/devise-2.0.4/app/views"
):
  app/controllers/users_controller.rb:73:in `follow_user'
  lib/ct_gems/dm-core-1.2.0/lib/dm-core.rb:263:in `block in repository'
  lib/ct_gems/dm-core-1.2.0/lib/dm-core/repository.rb:114:in `scope'
  lib/ct_gems/dm-core-1.2.0/lib/dm-core.rb:263:in `repository'


  Rendered /Users/hugo/.rvm/gems/ruby-1.9.2-p318/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/missing_template.erb within rescues/layout (0.5ms)

This is the code in my controller:

def follow_user
    @other_user = User.get(params[:user_id].to_i)
    current_user.follow(@other_user)

    respond_to do |format|
      format.html {redirect_to user_profile_path(@other_user)}
      format.js
    end
  end

This is my form...well not form but the link to follow function:

<% unless current_user == @user %>
  <div id="follow_form">
  <% if current_user.following?(@user) %>
    <%= render 'users/unfollow' %>
  <% else %>
    <%= render 'users/follow' %>
  <% end %>
  </div>
<% end %>

And this is one of the partials I am trying to render:

<%= link_to "Follow", user_follow_user_path(@user), :class => "btn btn-primary", :style => "margin-bottom:20px;", :remote => true %>

And this is the file to render the right button, I'm using this code my Michael's book:

$("#follow_form").html("<%= escape_javascript(render('users/unfollow')) %>")

However I am getting the error above that my partial is not found; can anyone explain to me why? Thanks

Upvotes: 0

Views: 544

Answers (2)

Hugs
Hugs

Reputation: 935

Bad reading on my part, the problem was the naming of my javascript file. The name of that has to match your controller action.

Upvotes: 0

Magicmarkker
Magicmarkker

Reputation: 1063

It's saying it's trying to render a template, which from my experience is a file in the views/ folder without the underscore preceding the name. Add the underscore to the start of the file name and do render :partial => 'users/follow' and see if that helps

Upvotes: 1

Related Questions