Tag: rjs

使用Ruby on Rails的Ajax弹出框

这是一个非常基本的问题,但我找不到一个好的答案。 我的Rails应用程序中有一个页面,其中有许多对象可以被“标记”。 单击标志按钮应显示一个带有确认,小forms等的小盒子。问题是我无法弄清楚如何使用RJS模板执行此操作。 我一直在使用page.insert_html,但这需要一个ID。 为了完成这项工作,我必须分配每个可以标记为唯一ID的东西。 这似乎不是很干净,仍然让我想知道确保只能显示一个表单,并且提交时框会消失。 这个问题有更简单的解决方案吗? 我本质上想要创建类似于SO上出现的标志框的标志。 对不起,我对RJS模板比较陌生。 谢谢。

对于使用哪种Prototype助手感到困惑

在阅读http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html后,我似乎无法找到我正在寻找的东西。 我有一个简单的模型,在消息列表达到24之后删除最旧的消息,模型就这么简单: class Message ‘updated_at DESC’) messages[24..-1].each {|p| p.destroy } if messages.size >= 24 end end 消息列表下方有一个消息表单,用于添加新消息。 我正在使用Prototype / RJS将新消息添加到列表顶部。 create.rjs: page.insert_html :top, :messages, :partial => @message page[@message].visual_effect :grow #page[dom_id(@messages)].replace :partial => @message page[:message_form].reset 我的index.html.erb非常简单: @messages %> “message_form” %> 添加新邮件时,它们看起来很好,但是当达到24邮件限制时,它只是不断添加邮件而不删除旧邮件。 理想情况下,我希望它们随着新的添加而淡出,但它们可以消失。 create.rjs中的注释行实际上有效,它删除了过期的消息但是在添加新消息时我失去了视觉效果。 有没有人有一个关于如何完成添加和删除这个简单列表中的消息的建议? 非常感谢帮助。 谢谢阅读。 PS:在这种情况下,periodic_call_remote会有所帮助吗?

在轨道上的ruby中的Ajax flash消息

我正在尝试显示一条Flash消息并使用Ajax呈现它,但是在我刷新页面之前 ,消息似乎没有出现。 这是我的create.rjs文件: page.insert_html :top, :feed_items, :partial => ‘shared/feed_item’, :object => @micropost page.replace_html :user_info, pluralize(current_user.microposts.count, “micropost”) page[:micropost_form].reset page.replace_html :notice, flash[:notice] flash.discard 这是我的应用程序布局视图的相关部分: <div class="flash “> 这是我的微控制器的相关部分: class MicropostsController [:create, :destroy] before_filter :authorized_user, :only => :destroy def create @micropost = current_user.microposts.build(params[:micropost]) respond_to do |format| if @micropost.save flash[:success] = “Micropost created!” format.html { redirect_to root_path } format.js […]

Ruby on Rails国家/州选择Enigma

我正在努力实现一些看似非常简单的事情,而且我已经在这几天打了我的脑袋。 我想要的最终结果是国家选择下拉列表,与状态选择下拉列表相关联,这样当选择给定国家/地区时,IF状态已知,那么这些状态将显示在选择下拉列表中,如果该国家/地区不知道任何州,然后会显示文本字段。 我觉得我快到了。 此时,接口实际上将根据人员的国家生成状态列表,除非它拒绝动态更新下拉列表。 我的视图中收集国家和州位置的部分看起来像: # _person_setup.html.erb * ‘width: 200px’, :id => ‘country_select’, :onchange => remote_function( :url => {:action => ‘update_states’}, :with => “‘country=’+value”)} %> ‘states’, :object => Carmen::states( Carmen::country_code( @person.country)), :locals => {:form => f} %> DIV中引用的部分如下: # _states.html.erb * * 最后,控制器代码用于动态更新状态列表: def update_states puts “Attempting to update states…” q = params[:country] states = […]

Rails 3.2.2不执行rjs

我正在阅读使用Rails第4版的实用敏捷Web开发这本书,但我正在使用Rails 3.2.2而不是书中推荐的3.0.5: ~$ ruby -v ruby 1.9.3p125 (2012-02-16) [i686-linux] ~$ rails -v Rails 3.2.2 我在包含AJAX重绘购物车而不重新加载页面时陷入困境。 这是line_items_controller.rb中的create动作: def create @cart = current_cart product = Product.find(params[:product_id]) @line_item = @cart.add_product(product.id) respond_to do |format| if @line_item.save format.html { redirect_to(store_url) } format.js format.json { render json: @line_item, status: :created, location: @line_item } else format.html { render action: “new” } format.json […]

Rails 3和RJS

我使用rails 3.0.0.beta 是否有任何新的语法来编写RJS,这是一个例子 def remote_create @photo = Photo.new(params[:photo]) respond_to do |format| if @photo.save # add @photo’s thumbnail to last import tag format.js { render :update do |page| page.insert_html :bottom, ‘polaroids’ , :partial => ‘polaroid’, :locals => {:photo => @photo} end } else #… end end end