I've been at the for hours now, trying to get vote_fu and running. I have finally made a vote on a voteable object(album), but I have to keep refreshing the page to see the effect of my Ajax knowledge with rails is basic and I have no idea where I'm going wrong with this any help would be great would be much appreciated!!!
The relevant code is as follows:
javascript file
application.js:
// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
jQuery.ajaxSetup({
'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})
jQuery(document).ready(function() {
$("#votes_ .album").bind('click', function(e)
});
|___________________________________________________________________________________________
jquery.js jquery-ui.js jrails.js
Layout/appliction.html.erb (javascript added to header)
<%= javascript_include_tag :defaults %>
<%= javascript_include_tag 'jquery.js', 'application.js' %>
view/votes
_album_vote.html.erb
<%#
# You can't vote if it is your quote,
# you are not logged in,
# or you have already voted on this item
unless album.user == current_user ||
current_user.voted_on?(@album)
%>
<%= link_to_remote "Vote Up",
:url => user_album_votes_path(album.user, album, :vote => :true, :format => :rjs),
:method => :post %>
<%= link_to_remote "Down",
#:url => current_user.vote_down_path(album), :vote => :false, :format => :rjs,
:url => user_album_votes_path(album.user, album, :vote => :false, :format => :rjs),
:method => :post
%>
<%# end %>
Votes: <%= @album.votes_for - @album.votes_against %>
|___________________________________________________________________________________________
view/album/show:
开发者_JS百科<div id="votes_<%= @album.id %>" class="album_votes">
<%= render :partial => "votes/album_vote", :locals => {:album => @album} %>
</div>
|___________________________________________________________________________________________
create.rjs
page.replace_html "votes_#{@album.id}", :partial => "album_vote", :locals => {:album => @album}
|___________________________________________________________________________________________
error.rjs
page.alert "Couldn't save your vote: You can only vote once, and you cannot vote for your own items."
|___________________________________________________________________________________________
I've tried playing with the ID #votes_ .album which I thought was name incorrectly but still it don't work not even an error, it's as if javascript is off !
Any help would be great!
Found the error on the server console:
NameError (uninitialized constant Mime::RJS):
app/controllers/votes_controller.rb:54:in `create'
app/controllers/votes_controller.rb:52:in `create'
I will concur this before lights out (bed time)!
If you like give me a helping hand!
Regards
Dan
It looks like you have issues with your basic jquery setup. The following two posts have certainly helped me up the jQuery learning curve:
jQuery Railscast
Beginners Guild to jQuery and Rails
These posts along with the amazing FireBug should get you there
Hope this helps.
精彩评论