Tag: ruby on rails 3

如何使用remote_function使用Rails 3进行Ajax调用?

我试图在选择框上进行onchange调用。对于我的应用程序,我使用jquery.js和rails.js来提及UJS。 但是生成的代码仍然是Prototype而不是jquery ajax调用。 我的代码如下所示: “name,id”).collect{|c| [c.name,c.id]}), :onchange => remote_function(:url => {:controller => “posts”, :action => “filter_post”, :filter =>”category”}, :with=>”‘category_id=’ + $(‘#category’).val()”) %> 由此生成的代码是: new Ajax.Request(‘/posts/filter_posts?filter=category’, {asynchronous:true, evalScripts:true, parameters:’category_id=’ + $(‘#category’).val() + ‘&authenticity_token=’ + encodeURIComponent(‘CCyYj1wqXtddK6pUV6bAxw0CqZ4lbBxDGQHp13Y/jMY=’)})

是否可以使用Ajax频繁刷新部分?

在后台,我希望它重新加载并显示有多少未读消息。 我希望没有刷新页面。 我的意思是使用ajax。 如果我在菜单中有这个,我怎么能每隔30秒刷新一次这个部分? <%= link_to sanitize(' ‘) + “received messages” + sanitize(‘ ‘+current_user.mailbox.inbox(:read => false).count(:id, :distinct => true).to_s+”), messages_received_path %> messages_controller.rb def received if params[:search] @messages = current_user.mailbox.inbox.search_messages(@search).page(params[:page]).per(10) else @messages = current_user.mailbox.inbox.page(params[:page]).per(10) end add_crumb ‘Messages Received’, messages_received_path @box = ‘inbox’ render :index end 更新: _ __ _ __ _ __ _ __ _ _ […]

jQuery发布到Rails

我的设置:Rails 3.0.9,Ruby 1.9.2,jQuery 1.6.2 我有一个表单,为用户显示多张照片和评论,我希望实现内联评论。 Summer 2011 Write a commenthttps://stackoverflow.com/questions/7237720/jquery-post-to-rails/… Seeing a movie Write a commenthttps://stackoverflow.com/questions/7237720/jquery-post-to-rails/… 我想在用户点击textarea字段中的回车键时提交一个AJAXpost。 这是我到目前为止的javascript(不完整) $(‘#newsfeed’).delegate(‘.comment_box’, ‘keydown’, function (event){ event.preventDefault(); $.post(‘/sub_comments’, https://stackoverflow.com/questions/7237720/jquery-post-to-rails/…); }); 我正在使用delegate方法,因为 内容可以用另一个AJAX调用替换。 我需要的是jQuery post方法的语法,假设我需要传递一些forms参数,比如说photo_id等等。假设我有办法访问params的值,那么post调用创建params的语法是什么Rails期待他们 这是标准的Rails位 sub_comments_controller.rb def new @sub_comment = SubComment.new respond_to do |format| format.html # new.html.erb format.js end end 另外我不想使用通常的 true) do |f| %> true) do |f| %>我可以添加的每个内联评论。 […]

link_to和remote => true + jquery:怎么样? 救命?

我试图在我的rails网站的索引上建立一个“用户”链接,以便它显示注册用户(User.all)但我希望它出现在网站的右侧部分,作为部分,在没有div从头开始加载整个页面。 我知道这可能是旧的原型和远程=>真,但使用Rails 3.1和jQuery(和资产)我不知道如何做到这一点。 任何人都可以帮助或告诉我教程的方法吗?