English 中文(简体)
何时使用错误确认书时
原标题:When to use render vs redirect_to when handling error validations

我的看法相当复杂,有多种形式、关于这些形式的许多鉴定、假想和其他特征。 在确认失败时,我想作成,因为你可以更具体地了解在形式上出现哪些错误。 然而,当我使用时,产生了不同的汇编错误,例如“未界定的方法`总页数'[]:Array”和“未界定的模式_名称”。 如果我不得不将这种情形转头换头,或者说,某些做法可以围绕在提出看法时出现的错误开展工作。 感谢一只面包车!

最佳回答

你们应当从自己的角度看待问题。

为什么使用<代码>render/code>而不是redirect:

  • when you use render, you pass the instantiated object

  • 该物体新制造或更新后,收到一些小军火

  • when attempting to save the object, validation was triggered and, if unsuccessful, added errors to the current instance

  • 页: 1

但是,当你使用直线时,你重新开始用一只新 st子,不了解前物体的记忆,不可能有任何魔mag:

  • 这两种目标都得到挽救,而且你能够从数据库中获取持续的数据。

  • 或者,如果无法挽救,你可以掌握你以前储存在届会期间的一些信息。


为了更贴近回答你的问题:在你使用之前,你必须对所有页上所需的物体进行即时检查。

如果缺少预期的假设变量,那么这种观点是正确的逻辑。

问题回答

First, these are not compiler error - its run-time errors.
Second, you should either check your data in the controller to make sure its being served properly for rendering OR do some conditional blocks in the view in order to cope with this different data structures.

最后,redirect_to只是将用户移至周围的一种方法,可在此加以使用,但你仍需要处理这些错误,即便是在改头到网页上。

HTH





相关问题
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: ...

热门标签