lundi 9 mars 2015

Rails Acts As Votable Ajax Issue


Vote count:

0




I have the Acts As Votable gem working in a social app I am developing and I am trying to get it to work via ajax so the page does not refresh, causing the reader to lose their place.


If I refresh the page the vote went through but I'm getting the following error and I don't understand what it means, or how to fix it:



Template is missing

Missing template posts/upvote, application/upvote with {:locale=>[:en], :formats=>[:js, "application/ecmascript", "application/x-ecmascript", :html, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}.


In my Posts Controller:



def upvote
@post = Post.find(params[:id])
@post.liked_by current_user
end


My my view:



<%= link_to like_post_path(post), class: "like", method: :put, :remote => true do %>
<button type="button" class="btn btn-primary btn-sm" aria-label="Left Align">
<i class="fa fa-heart"></i> Mark Voted For
| <%= post.get_upvotes.size %>
</button>
<% end %>


At the bottom of my view (for now):



<script>
$('.like')
.on('ajax:send', function () { $(this).addClass('loading'); })
.on('ajax:complete', function () { $(this).removeClass('loading'); })
.on('ajax:error', function () { $(this).after('<div class="error">There was an issue.</div>'); })
.on('ajax:success', function (data) { $(this).html(data.count); });
</script>


My routes:



resources :posts, only: [:create, :edit, :update, :destroy] do
member do
put 'like' => 'posts#upvote'
end
end


Thanks for any help you can offer.



asked 39 secs ago







Rails Acts As Votable Ajax Issue

Aucun commentaire:

Enregistrer un commentaire