English 中文(简体)
铁路:对已销毁物体采取其他行动时处理例外情形的共同办法?
原标题:Rails: common approach for handling exceptions in restful actions on objects that have been destroyed?

铁路非常常见的情况是:<条码>物体-控制器<>/条码>控制器有<条码>dit和<条码>destroy。 类似行动:

def edit
  @object = Object.find(params[:id])
end

def destroy
  @object = Object.find(params[:id])

  @object.destroy
  redirect_to :back
end

与此相关的观点是:

<%= link_to "Edit the Object", edit_object_path(object) %>
<%= link_to "Delete", object, :confirm =>  Are you sure? , :method => :delete %>

很容易对此进行打击。 如果我打开两个浏览器窗口,即A和B,销毁浏览器A中带有“脱钩”链接的物体,然后在浏览器B中发布“Edit”链接,find(<>

www.un.org/Depts/DGACM/index_spanish.htm 增加Jakub的建议

有若干办法处理这一问题:

  1. catch the exception and recover gracefully in the edit action
  2. use @object = find(:first, "conditions... etc. and test the @object in the edit action
  3. use a general 404

但是,鉴于这是一个共同的模式,我很想知道其他民间人士如何应对这种情况。

问题回答

你在public/404.html<<>>>>>><>>>上编辑了404页,这可合理地解释,当事人试图查阅的不是再有的。 这是总体解决办法。 然而,你的领域可以允许例如软性删除,然后,你可以主动提出把记录分离出来。 检查这块树脂(一般在以前的过滤器中执行)。





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...