开发者

Rails update page w/o prototype?

I'm trying (still) to get ajaxful-rating to work with my rails installation. I did not install my app with prototype because I like jQuery.

The tutorial (and everyone else) has said to use this to render the update

render :update do |page|
  page.replace_html id, ratings_for(@entry, :wrap => false, :dimension => params[:dimension])
  page.visual_effect :highlight, id
end

However, I get a 'undefined local variable or method 'id''...I can get the gem working without ajax by doing a standard:

respond_to do |format|
  format.html { redirect_to @entry }
  format.js { render :layout => false}
end

I guess I could always just do a jQuery.ajax call, but I'd like to implement this as tightly into my rails app as possible--I want to learn to do it the right way. :)

Please please please help. 开发者_如何学Python I've definitely resorted to begging for help.


I haven't tried it since I prefer to decouple everything (that is, the page should work without being depending on javascript at all), but have a look at the jquery rails plugin http://rubygems.org/gems/jquery-rails

It might do what you want since it is supposed to be a complete replacement for prototype.

However, the error sounds like you are missing some initialization. Try with using params[:id] instead.


id is supposed to be the dom id of the ratings element that you are trying to replace with new ratings. So look what the id is and replace id in your code with that string.

You could also write the JS code manually without relying on RJS.

Something like this

$("#YOUR_ID_HERE").html("<%= escape_javascript ratings_for(@entry, :wrap => false, :dimension => params[:dimension]) %>");
$("#YOUR_ID_HERE").effect("highlight");

Put this code in your view, name it your_action.js.erb (replace the your_action with your action name of course). Then your standard respond_to block should work

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜