Vote_fu和Ajax请求

时间:2010-03-04 12:39:23

标签: ruby-on-rails

我现在已经待了好几个小时,试图投票并运行。我终于对一个可投票的对象(专辑)进行了投票,但是我必须不断更新页面以查看我对使用rails的Ajax知识的影响是基本的,我不知道我在哪里出错这个任何帮助都会非常感谢!!!

相关代码如下:

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

Layout / 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'

我会在熄灯前(睡觉时间)同意这个!

如果你愿意帮助我!

此致

1 个答案:

答案 0 :(得分:0)

您的基本jquery设置似乎有问题。以下两篇文章肯定帮助我完成了jQuery学习曲线:

jQuery Railscast

Beginners Guild to jQuery and Rails

这些帖子以及惊人的FireBug应该可以帮助你

希望这有帮助。