相關問題:Vote_fu and Ajax requestsAjax and vote_fu |在語句前缺失
我的Ajax請求似乎有問題。 我想要做的是在事件點擊投票提交一個投票,然後刷新頁面刷新頁面。
votes_controller.rb:
def create
@album = Album.find(params[:album_id])
respond_to do |format|
if current_user.vote(@album, params[:vote])
format.js { render :action => "create", :vote => @vote }
format.html { redirect_to([@album.user, @album]) }
#format.xml { render :xml => @album, :status => :created, :location => @album }
else
format.js { render :action => "error" }
format.html { render :action => "new" }
format.xml { render :xml => @vote.errors, :status => :unprocessable_entity }
end
end
end
鏈接|爲查看專輯顯示:
<%= link_to_remote "Vote Up",
:url => user_album_votes_path(album.user, album,
:vote => :true, :format => :js),
:method => :post %>
的application.js
jQuery.ajaxSetup({
'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})
jQuery(document).ready(function() {
$("#votes_.album").bind('click');
})
create.js
page.replace_html "#votes_{@album.id}",
:partial => "album_vote",
:locals => {:album => @album}
這是我收到以下錯誤信息:
missing ; before statement
[Break on this error] page.replace_html "#votes_#{@album.id}", ...bum_vote", :locals => {:album => @album}
我不知道什麼是布萊恩g在這裏錯了我一直在關注vote_fu文檔的 中的很多例子,但仍有問題。在create.js做出
http://github.com/peteonrails/vote_fu/tree#readme
一個修正
現在有另一個錯誤:
沒有錯誤已經移到了votes_controller
NoMethodError (You have a nil object when you didn't expect it!
<br />
The error occurred while evaluating nil.vote):
app/controllers/votes_controller.rb:53:in `create'
app/controllers/votes_controller.rb:52:in `create'
<br />
Rendered rescues/_trace (128.4ms)
Rendered rescues/_request_and_response (0.4ms)
Rendering rescues/layout (internal_server_error)
這些生產線都在創建操作,看起來非常好!!
我如何得到這個工作?
方面
丹
嘗試過,它仍然不起作用! 感謝SamChandra – MrThomas 2010-03-05 11:44:13