我已经呆了好几个小时了,试着让vote_fu运行起来。我终于对一个可投票的对象(相册)进行了投票,但我必须不断刷新页面,以看到我的Ajax知识对于rails的影响是基本的,我不知道我在哪里出错了,任何帮助都会是非常好的!
有关守则如下:
javascript文件
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
布局/appliction.html.erb(将javascript添加到标头)
<%= javascript_include_tag :defaults %>
<%= javascript_include_tag 'jquery.js', 'application.js' %>意见/投票
_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 %>|___________________________________________________________________________________________
查看/相册/展示:
<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."|___________________________________________________________________________________________
我试过使用ID #votes_ .album,我认为它的名称是错误的,但是它仍然不能工作,甚至一个错误都没有,就好像javascript关闭了一样!
任何帮助都会很好!
在服务器控制台上找到错误:
NameError (uninitialized constant Mime::RJS):
app/controllers/votes_controller.rb:54:in `create'
app/controllers/votes_controller.rb:52:in `create'在灯亮(睡觉时间)之前,我会同意的!
如果你愿意的话,帮我一把!
问候
丹
发布于 2010-03-04 17:23:08
看起来,您的基本jquery设置存在问题。以下两篇文章无疑帮助我提高了jQuery的学习曲线:
jQuery铁路
jQuery和Rails初学者协会
这些帖子和令人惊叹的FireBug应该能帮你达到目的
希望这能有所帮助。
https://stackoverflow.com/questions/2379270
复制相似问题