English 中文(简体)
铁路中的比较特征
原标题:add comparison feature in rails

i m 可能会增加某种特征。 i m 在购买/销售地点工作,希望能够比较员额。 一、截至目前的情况

在员额方面:

<%= button_to "Add to Compare", :action => "addCompare" %>

in the corresponding controller:

@@a = Array.new()

def addCompare
   @@a << Post.id
end

因此,所有想做的是,在ar里的@a中增加这个员额。 在测试时,在“Add to Compare”纽芬兰和伊米欢迎:

模板缺失

缺少模板员额 比较:{:re=>[:en, :en],:formats=> [:html],:handlers=>[:rxml, :rjs, :builder, :rhtml, :erb]} in view paths “home/mja32/470repo/traders/app/views”,“var/lib/gems/1.8/gems/devs-1.4.2/app/views”

因此,我猜测它试图改变观点。 我如何阻止它这样做? 我都希望这一纽伦这样做,就是在阵列中增加这一职位,而不要再增加。

提前感谢,

问题

最佳回答

首先,将持久性数据储存在控制器的类别变量中,就没有达到你想要它的方式。 没有任何保证<代码>@a在您的下一个<代码>addCompare上成为同一阵列。 电话:例如,您的下一个<代码>addCompare电话可由不同程序处理。 另外,如果两个不同的客户打电话addCompare,情况如何? 你们是否真的想要把自己的数据混在一起。 不可原谅。 您的第一项任务是将@a替换成一个真正的用户固定储存。

如果你想完全从你的控制人那里回来,那么,在您的:

render :nothing => true, :status => :ok

这将告诉铁路公司,已经做了一些事情,因此没有必要尝试违约的提交行动(即提供<条码>指令/addCompare观点),并且只向客户退回200条地位法。

Once that s in place, you ll probably want to AJAXify your button with :remote => true:

:remote - If set to true, will allow the Unobtrusive JavaScript drivers to control the submit behaviour. By default this behaviour is an ajax submit.

因此:

<%= button_to "Add to Compare", { :action => "addCompare" }, { :remote => true } %>

注:button_to looks:

button_to(name, options = {}, html_options = {})

options/code> 因此,你必须用<代码>{><>>>>/代码”明确标明序号;你只能将<条码>中<>options/code>列入:

<%= button_to "Add to Compare", { :action => "addCompare" }, :remote => true %>

but I prefer the consistency of wrapping them both by hand.

问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签