This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
So first things first, I have no idea how to use javascript. All I really know about it is that it allows me to change things without refreshing the page. I have no idea how to get my models/variables into javascript or where it falls in the timeline of asset service.
What I want is for the div containing the value @video.plusminus to update with the new value of @video.plusminus after the vote has been recorded.
show.html.erb:
<div>
<%= link_to "/videos/#{@video.id}/upvote", method: 'post', remote: true do %>
<i class="glyphicon glyphicon-chevron-up"></i>
<% end %>
<div id="score"><%=@score%></div>
videos_controller.rb
def upvote
@video = Video.find(params[:id])
if current_user.voted_against?(@video)
current_user.vote_exclusively_for(@video)
elsif current_user.voted_on?(@video)
current_user.unvote_for(@video)
else
current_user.vote_for(@video)
end
respond_to do |format|
format.js
end
end
upvote.js.erb:
$("score").update.("<%= escape_javascript(render(@video.plusminus)) %>");
When I click the link, nothing happens, and I don't know why. If someone could explain the right way to do this to me, I'd be much obliged. I've never had to use javascript before and it's frustrating as hell.
Subreddit
Post Details
- Posted
- 10 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/rails/comme...