relate question: http://stackoverflow.com/questions/2379270/vote-fu-and-ajax-requests
There seems to be something wrong with my Ajax request. What I 'm trying to do is on event click vote submit a vote then update page with out refreshing the page.
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 | for view album show :
<%= 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}
This is the following error message which I'm getting:
missing ; before statement
[Break on this error] page.replace_html "#votes_#{@album.id}", ...bum_vote", :locals => {:album => @album}
I'm not sure what is going wrong here I have been following many example from the vote_fu doc's still having problems.
http://github.com/peteonrails/vote_fu/tree#readme
one amendment made on create.js
there is now another error:
No the error has moved over to the 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)
These lines are on the create action, which looks perfectly fine!?
How do I get this to work?
Regard
Dan