我试图让我的项目尽可能没有错误,但我所有的 phtml 文件都包含 <nav> , <aside> , <article>和其他 HTML5 标签会导致错误。
如何配置验证器以识别这些新元素?
已尝试向此处的源请求支持
http://forums.zend.com/viewtopic.php?f=59&t=10463
目前没有答案
最佳答案
使用 HTML5 DTD来自 Komodo,它是 XHTML DTD 的扩展,作为 Eclipse XML Catalog 中的新映射.
<!--
HTML 5 DTD
This is the same as HTML 4 Transitional except for
updates for the HTML 5 specication.
-->
<!--================ Character mnemonic entities =========================-->
<!ENTITY % HTMLlat1 PUBLIC
"-//W3C//ENTITIES Latin 1 for XHTML//EN"
"html5-lat1.ent">
%HTMLlat1;
<!ENTITY % HTMLsymbol PUBLIC
"-//W3C//ENTITIES Symbols for XHTML//EN"
"html5-symbol.ent">
%HTMLsymbol;
<!ENTITY % HTMLspecial PUBLIC
"-//W3C//ENTITIES Special for XHTML//EN"
"html5-special.ent">
%HTMLspecial;
<!--================== Imported Names ====================================-->
<!ENTITY % ContentType "CDATA">
<!-- media type, as per [RFC2045] -->
<!ENTITY % ContentTypes "CDATA">
<!-- comma-separated list of media types, as per [RFC2045] -->
<!ENTITY % Charset "CDATA">
<!-- a character encoding, as per [RFC2045] -->
<!ENTITY % Charsets "CDATA">
<!-- a space separated list of character encodings, as per [RFC2045] -->
<!ENTITY % LanguageCode "NMTOKEN">
<!-- a language code, as per [RFC3066] -->
<!ENTITY % Character "CDATA">
<!-- a single character, as per section 2.2 of [XML] -->
<!ENTITY % Number "CDATA">
<!-- one or more digits -->
<!ENTITY % Date "CDATA">
<!-- one or more digits -->
<!ENTITY % LinkTypes "(alternate | archives | author | bookmark | contact | external | first | help | icon | index | last | license | next | nofollow | noreferrer | pingback | prefetch | prev | search | stylesheet | sidebar | tag | up)">
<!-- space-separated list of link types -->
<!ENTITY % MediaDesc "(all|braille|embossed|handheld|print|projection|screen|speech|tty|tv)">
<!-- single or comma-separated list of media descriptors -->
<!ENTITY % URI "CDATA">
<!-- a Uniform Resource Identifier, see [RFC2396] -->
<!ENTITY % UriList "CDATA">
<!-- a space separated list of Uniform Resource Identifiers -->
<!ENTITY % Datetime "CDATA">
<!-- date and time information. ISO date format -->
<!ENTITY % Script "CDATA">
<!-- script expression -->
<!ENTITY % StyleSheet "CDATA">
<!-- style sheet data -->
<!ENTITY % Text "CDATA">
<!-- used for titles etc. -->
<!ENTITY % FrameTarget "(_blank | _parent | _self | _top)">
<!-- render in this frame -->
<!ENTITY % Length "CDATA">
<!-- nn for pixels or nn% for percentage length -->
<!ENTITY % MultiLength "CDATA">
<!-- pixel, percentage, or relative -->
<!ENTITY % Pixels "CDATA">
<!-- integer representing length in pixels -->
<!ENTITY % Boolean "(true|false)">
<!-- these are used for image maps -->
<!ENTITY % Shape "(rect|circle|poly|default)">
<!ENTITY % Coords "CDATA">
<!-- comma separated list of lengths -->
<!-- a color using sRGB: #RRGGBB as Hex values -->
<!ENTITY % Color "CDATA">
<!-- There are also 16 widely known color names with their sRGB values:
Black = #000000 Green = #008000
Silver = #C0C0C0 Lime = #00FF00
Gray = #808080 Olive = #808000
White = #FFFFFF Yellow = #FFFF00
Maroon = #800000 Navy = #000080
Red = #FF0000 Blue = #0000FF
Purple = #800080 Teal = #008080
Fuchsia= #FF00FF Aqua = #00FFFF
-->
<!--=================== Generic Attributes ===============================-->
<!-- core attributes common to most elements
id document-wide unique id
class space separated list of classes
style associated style info
title advisory title/amplification
-->
<!ENTITY % coreattrs
"id ID #IMPLIED
class CDATA #IMPLIED
style %StyleSheet; #IMPLIED
title %Text; #IMPLIED"
>
<!-- internationalization attributes
lang language code (backwards compatible)
xml:lang language code (as per XML 1.0 spec)
dir direction for weak/neutral text
-->
<!ENTITY % i18n
"lang %LanguageCode; #IMPLIED
xml:lang %LanguageCode; #IMPLIED
dir (ltr|rtl) #IMPLIED"
>
<!-- attributes for common UI events
onclick a pointer button was clicked
ondblclick a pointer button was double clicked
onmousedown a pointer button was pressed down
onmouseup a pointer button was released
onmousemove a pointer was moved onto the element
onmouseout a pointer was moved away from the element
onkeypress a key was pressed and released
onkeydown a key was pressed down
onkeyup a key was released
-->
<!ENTITY % events
"onclick %Script; #IMPLIED
ondblclick %Script; #IMPLIED
onmousedown %Script; #IMPLIED
onmouseup %Script; #IMPLIED
onmouseover %Script; #IMPLIED
onmousemove %Script; #IMPLIED
onmouseout %Script; #IMPLIED
onkeypress %Script; #IMPLIED
onkeydown %Script; #IMPLIED
onkeyup %Script; #IMPLIED
<!-- HTML 5 Mouse Events - Events triggered by a mouse, or similar user actions: -->
ondrag %Script; #IMPLIED <!-- Script to be run when an element is dragged -->
ondragend %Script; #IMPLIED <!-- Script to be run at the end of a drag operation -->
ondragenter %Script; #IMPLIED <!-- Script to be run when an element has been dragged to a valid drop target -->
ondragleave %Script; #IMPLIED <!-- Script to be run when an element leaves a valid drop target -->
ondragover %Script; #IMPLIED <!-- Script to be run when an element is being dragged over a valid drop target -->
ondragstart %Script; #IMPLIED <!-- Script to be run at the start of a drag operation -->
ondrop %Script; #IMPLIED <!-- Script to be run when dragged element is being dropped -->
onmousewheel %Script; #IMPLIED <!-- Script to be run when the mouse wheel is being rotated -->
onscroll %Script; #IMPLIED <!-- Script to be run when an element's scrollbar is being scrolled -->
"
>
<!-- attributes for elements that can get the focus
accesskey accessibility key character
tabindex position in tabbing order
onfocus the element got the focus
onblur the element lost the focus
-->
<!ENTITY % focus
"accesskey %Character; #IMPLIED
tabindex %Number; #IMPLIED
onfocus %Script; #IMPLIED
onblur %Script; #IMPLIED"
>
<!-- HTML 5 core attributes -->
<!ENTITY % html5attrs
"contenteditable %Boolean; #IMPLIED
contextmenu ID #IMPLIED
draggable (true | false | auto) #IMPLIED
hidden (hidden) #IMPLIED
item CDATA #IMPLIED
itemprop CDATA #IMPLIED
spellcheck %Boolean; #IMPLIED
subject ID #IMPLIED
contextmenu ID #IMPLIED
contextmenu ID #IMPLIED
contextmenu ID #IMPLIED
contextmenu ID #IMPLIED
"
>
<!-- Media Events - Events triggered by medias like videos, images and audio.
Applies to all HTML 5 elements, but is most common in media elements, such
as audio, embed, img, object, and video. -->
<!ENTITY % html5mediaevents
"onabort %Script; #IMPLIED <!-- Script to be run on an abort event -->
oncanplay %Script; #IMPLIED <!-- Script to be run when media can start play, but might has to stop for buffering -->
oncanplaythrough %Script; #IMPLIED <!-- Script to be run when media can be played to the end, without stopping for buffering -->
ondurationchange %Script; #IMPLIED <!-- Script to be run when the length of the media is changed -->
onemptied %Script; #IMPLIED <!-- Script to be run when a media resource element suddenly becomes empty (network errors, errors on load etc.) -->
onended %Script; #IMPLIED <!-- Script to be run when media has reach the end -->
onerror %Script; #IMPLIED <!-- Script to be run when an error occurs during the loading of an element -->
onloadeddata %Script; #IMPLIED <!-- Script to be run when media data is loaded -->
onloadedmetadata %Script; #IMPLIED <!-- Script to be run when the duration and other media data of a media element is loaded -->
onloadstart %Script; #IMPLIED <!-- Script to be run when the browser starts to load the media data -->
onpause %Script; #IMPLIED <!-- Script to be run when media data is paused -->
onplay %Script; #IMPLIED <!-- Script to be run when media data is going to start playing -->
onplaying %Script; #IMPLIED <!-- Script to be run when media data has start playing -->
onprogress %Script; #IMPLIED <!-- Script to be run when the browser is fetching the media data -->
onratechange %Script; #IMPLIED <!-- Script to be run when the media data's playing rate has changed -->
onreadystatechange %Script; #IMPLIED <!-- Script to be run when the ready-state changes -->
onseeked %Script; #IMPLIED <!-- Script to be run when a media element's seeking attribute is no longer true, and the seeking has ended -->
onseeking %Script; #IMPLIED <!-- Script to be run when a media element's seeking attribute is true, and the seeking has begun -->
onstalled %Script; #IMPLIED <!-- Script to be run when there is an error in fetching media data (stalled) -->
onsuspend %Script; #IMPLIED <!-- Script to be run when the browser has been fetching media data, but stopped before the entire media file was fetched -->
ontimeupdate %Script; #IMPLIED <!-- Script to be run when media changes its playing position -->
onvolumechange %Script; #IMPLIED <!-- Script to be run when media changes the volume, also when volume is set to "mute" -->
onwaiting %Script; #IMPLIED <!-- Script to be run when media has stopped playing, but is expected to resume -->
"
>
<!ENTITY % attrs "%coreattrs; %i18n; %events; %html5attrs;">
<!--=================== Text Elements ====================================-->
<!ENTITY % special.extra
"object | img | map | iframe">
<!ENTITY % special.basic
"br | span | bdo">
<!ENTITY % special
"%special.basic; | %special.extra;">
<!ENTITY % fontstyle.basic "small | i | b | u">
<!ENTITY % fontstyle "%fontstyle.basic;">
<!ENTITY % phrase.extra "sub | sup">
<!ENTITY % phrase.basic "em | strong | dfn | code | q |
samp | kbd | var | cite | abbr | acronym">
<!ENTITY % phrase "%phrase.basic; | %phrase.extra;">
<!ENTITY % inline.forms "input | output | select | textarea | label | button |
datetime | datetime-local | data | month | week |
time | number | range | email | url | menu |
datalist">
<!-- these can occur at block or inline level -->
<!ENTITY % misc.inline "ins | del | script">
<!-- these can only occur at block level -->
<!ENTITY % misc "noscript | %misc.inline;">
<!ENTITY % inline "a | %special; | %fontstyle; | %phrase; | %inline.forms;">
<!-- %Inline; covers inline or "text-level" elements -->
<!ENTITY % Inline "(#PCDATA | %inline; | %misc.inline;)*">
<!--================== Block level elements ==============================-->
<!ENTITY % heading "h1|h2|h3|h4|h5|h6">
<!ENTITY % lists "ul | ol | dl">
<!ENTITY % blocktext "pre | hr | blockquote | address | article | aside |
summary | mark">
<!ENTITY % block
"p | %heading; | div | %lists; | %blocktext; | fieldset | table |
header | footer | section | hgroup | main | nav | dialog | figure |
datagrid | canvas | audio | video | source | embed | keygen |
progress | ruby">
<!-- %Flow; mixes block and inline and is used for list items etc. -->
<!ENTITY % Flow "(#PCDATA | %block; | form | %inline; | %misc;)*">
<!--================== Content models for exclusions =====================-->
<!-- a elements use %Inline; excluding a -->
<!ENTITY % a.content
"(#PCDATA | %special; | %fontstyle; | %phrase; | %inline.forms; | %misc.inline;)*">
<!-- pre uses %Inline excluding img, object, big, small -->
<!ENTITY % pre.content
"(#PCDATA | a | %special.basic; | %fontstyle.basic; | %phrase.basic; |
%inline.forms; | %misc.inline;)*">
<!-- form uses %Flow; excluding form -->
<!ENTITY % form.content "(#PCDATA | %block; | %inline; | %misc;)*">
<!-- button uses %Flow; but excludes a, form, form controls, iframe -->
<!ENTITY % button.content
"(#PCDATA | p | %heading; | div | %lists; | %blocktext; |
table | datagrid | br | span | bdo | object | img | map |
%fontstyle; | %phrase; | %misc;)*">
<!--================ Document Structure ==================================-->
<!-- the namespace URI designates the document profile -->
<!ELEMENT html (head, body)>
<!ATTLIST html
%i18n;
id ID #IMPLIED
xmlns %URI; #FIXED 'http://www.w3.org/1999/xhtml'
<!-- HTML 5 attributes -->
manifest %URI; #IMPLIED
>
<!--================ Document Head =======================================-->
<!ENTITY % head.misc "(script|style|meta|link|object)*">
<!-- content model is %head.misc; combined with a single
title and an optional base element in any order -->
<!ELEMENT head (%head.misc;,
((title, %head.misc;, (base, %head.misc;)?) |
(base, %head.misc;, (title, %head.misc;))))>
<!ATTLIST head
%i18n;
id ID #IMPLIED
profile %URI; #IMPLIED
>
<!-- The title element is not considered part of the flow of text.
It should be displayed, for example as the page header or
window title. Exactly one title is required per document.
-->
<!ELEMENT title (#PCDATA)>
<!ATTLIST title
%i18n;
id ID #IMPLIED
>
<!-- document base URI -->
<!ELEMENT base EMPTY>
<!ATTLIST base
id ID #IMPLIED
href %URI; #IMPLIED
target %FrameTarget; #IMPLIED
>
<!-- generic metainformation -->
<!ELEMENT meta EMPTY>
<!ATTLIST meta
%i18n;
id ID #IMPLIED
http-equiv CDATA #IMPLIED
name CDATA #IMPLIED
content CDATA #REQUIRED
<!-- HTML 5 attributes -->
charset %Charset; #IMPLIED
>
<!--
Relationship values can be used in principle:
a) for document specific toolbars/menus when used
with the link element in document head e.g.
start, contents, previous, next, index, end, help
b) to link to a separate style sheet (rel="stylesheet")
c) to make a link to a script (rel="script")
d) by stylesheets to control how collections of
html nodes are rendered into printed documents
e) to make a link to a printable version of this document
e.g. a PostScript or PDF version (rel="alternate" media="print")
-->
<!ELEMENT link EMPTY>
<!ATTLIST link
%attrs;
href %URI; #IMPLIED
hreflang %LanguageCode; #IMPLIED
type %ContentType; #IMPLIED
rel %LinkTypes; #IMPLIED
media %MediaDesc; #IMPLIED
<!-- HTML 5 attributes -->
sizes %Number; #IMPLIED
>
<!-- style info, which may include CDATA sections -->
<!ELEMENT style (#PCDATA)>
<!ATTLIST style
%i18n;
id ID #IMPLIED
type (text/css) #REQUIRED
media %MediaDesc; #IMPLIED
<!-- HTML 5 attributes -->
scoped (scoped) #IMPLIED
>
<!-- script statements, which may include CDATA sections -->
<!ELEMENT script (#PCDATA)>
<!ATTLIST script
id ID #IMPLIED
charset %Charset; #IMPLIED
type (text/javascript) #REQUIRED
language CDATA #IMPLIED
src %URI; #IMPLIED
defer (defer) #IMPLIED
<!-- HTML 5 attributes -->
async (async) #IMPLIED
>
<!-- alternate content container for non script-based rendering -->
<!ELEMENT noscript %Flow;>
<!ATTLIST noscript
%attrs;
>
<!--======================= Frames =======================================-->
<!-- inline subwindow -->
<!ELEMENT iframe %Flow;>
<!ATTLIST iframe
%coreattrs;
%html5attrs;
name NMTOKEN #IMPLIED
src %URI; #IMPLIED
height %Length; #IMPLIED
width %Length; #IMPLIED
<!-- HTML 5 attributes -->
sandbox (allow-forms | allow-same-origin | allow-scripts) #IMPLIED
seamless CDATA #IMPLIED
srcdoc CDATA #IMPLIED
>
<!--=================== Document Body ====================================-->
<!ELEMENT body %Flow;>
<!ATTLIST body
%attrs;
onload %Script; #IMPLIED
onunload %Script; #IMPLIED
<!-- HTML 5 Window Event Attributes -->
onafterprint %Script; #IMPLIED <!-- Script to be run after the document is printed -->
onbeforeprint %Script; #IMPLIED <!-- Script to be run before the document is printed -->
onbeforeonload %Script; #IMPLIED <!-- Script to be run before the document loads -->
onerror %Script; #IMPLIED <!-- Script to be run when an error occur -->
onhaschange %Script; #IMPLIED <!-- Script to be run when the document has change -->
onmessage %Script; #IMPLIED <!-- Script to be run when the message is triggered -->
onoffline %Script; #IMPLIED <!-- Script to be run when the document goes offline -->
ononline %Script; #IMPLIED <!-- Script to be run when the document comes online -->
onpagehide %Script; #IMPLIED <!-- Script to be run when the window is hidden -->
onpageshow %Script; #IMPLIED <!-- Script to be run when the window becomes visible -->
onpopstate %Script; #IMPLIED <!-- Script to be run when the window's history changes -->
onredo %Script; #IMPLIED <!-- Script to be run when the document performs a redo -->
onresize %Script; #IMPLIED <!-- Script to be run when the window is resized -->
onstorage %Script; #IMPLIED <!-- Script to be run when a document loads -->
onundo %Script; #IMPLIED <!-- Script to be run when a document performs an undo -->
onunload %Script; #IMPLIED <!-- Script to be run when the user leaves the document -->
>
<!ELEMENT div %Flow;> <!-- generic language/style container -->
<!ATTLIST div
%attrs;
>
<!--=================== Paragraphs =======================================-->
<!ELEMENT p %Inline;>
<!ATTLIST p
%attrs;
>
<!--=================== Headings =========================================-->
<!--
There are six levels of headings from h1 (the most important)
to h6 (the least important).
-->
<!ELEMENT h1 %Inline;>
<!ATTLIST h1
%attrs;
>
<!ELEMENT h2 %Inline;>
<!ATTLIST h2
%attrs;
>
<!ELEMENT h3 %Inline;>
<!ATTLIST h3
%attrs;
>
<!ELEMENT h4 %Inline;>
<!ATTLIST h4
%attrs;
>
<!ELEMENT h5 %Inline;>
<!ATTLIST h5
%attrs;
>
<!ELEMENT h6 %Inline;>
<!ATTLIST h6
%attrs;
>
<!--=================== Lists ============================================-->
<!-- Unordered list -->
<!ELEMENT ul (li)+>
<!ATTLIST ul
%attrs;
>
<!-- Ordered (numbered) list -->
<!ELEMENT ol (li)+>
<!ATTLIST ol
%attrs;
start %Number; #IMPLIED
<!-- HTML 5 attributes -->
reversed (reversed) #IMPLIED
>
<!-- list item -->
<!ELEMENT li %Flow;>
<!ATTLIST li
%attrs;
value %Number; #IMPLIED
>
<!-- definition lists - dt for term, dd for its definition -->
<!ELEMENT dl (dt|dd)+>
<!ATTLIST dl
%attrs;
>
<!ELEMENT dt %Inline;>
<!ATTLIST dt
%attrs;
>
<!ELEMENT dd %Flow;>
<!ATTLIST dd
%attrs;
>
<!--=================== Address ==========================================-->
<!-- information on author -->
<!ELEMENT address (#PCDATA | %inline; | %misc.inline; | p)*>
<!ATTLIST address
%attrs;
>
<!--=================== Horizontal Rule ==================================-->
<!ELEMENT hr EMPTY>
<!ATTLIST hr
%attrs;
>
<!--=================== Preformatted Text ================================-->
<!-- content is %Inline; excluding
"img|object|small|sub|sup" -->
<!ELEMENT pre %pre.content;>
<!ATTLIST pre
%attrs;
>
<!--=================== Block-like Quotes ================================-->
<!ELEMENT blockquote %Flow;>
<!ATTLIST blockquote
%attrs;
cite %URI; #IMPLIED
>
<!--=================== Inserted/Deleted Text ============================-->
<!--
ins/del are allowed in block and inline content, but its
inappropriate to include block content within an ins element
occurring in inline content.
-->
<!ELEMENT ins %Flow;>
<!ATTLIST ins
%attrs;
cite %URI; #IMPLIED
datetime %Datetime; #IMPLIED
>
<!ELEMENT del %Flow;>
<!ATTLIST del
%attrs;
cite %URI; #IMPLIED
datetime %Datetime; #IMPLIED
>
<!--================== The Anchor Element ================================-->
<!-- content is %Inline; except that anchors shouldn't be nested -->
<!ELEMENT a %a.content;>
<!ATTLIST a
%attrs;
%focus;
href %URI; #IMPLIED
hreflang %LanguageCode; #IMPLIED
rel %LinkTypes; #IMPLIED
target %FrameTarget; #IMPLIED
<!-- HTML 5 attributes -->
media CDATA #IMPLIED
ping %URI; #IMPLIED
type %ContentType; #IMPLIED
>
<!--===================== Inline Elements ================================-->
<!ELEMENT span %Inline;> <!-- generic language/style container -->
<!ATTLIST span
%attrs;
>
<!ELEMENT bdo %Inline;> <!-- I18N BiDi over-ride -->
<!ATTLIST bdo
%coreattrs;
%html5attrs;
%events;
lang %LanguageCode; #IMPLIED
xml:lang %LanguageCode; #IMPLIED
dir (ltr|rtl) #REQUIRED
>
<!ELEMENT br EMPTY> <!-- forced line break -->
<!ATTLIST br
%coreattrs;
%html5attrs;
>
<!ELEMENT em %Inline;> <!-- emphasis -->
<!ATTLIST em %attrs;>
<!ELEMENT strong %Inline;> <!-- strong emphasis -->
<!ATTLIST strong %attrs;>
<!ELEMENT dfn %Inline;> <!-- definitional -->
<!ATTLIST dfn %attrs;>
<!ELEMENT code %Inline;> <!-- program code -->
<!ATTLIST code %attrs;>
<!ELEMENT samp %Inline;> <!-- sample -->
<!ATTLIST samp %attrs;>
<!ELEMENT kbd %Inline;> <!-- something user would type -->
<!ATTLIST kbd %attrs;>
<!ELEMENT var %Inline;> <!-- variable -->
<!ATTLIST var %attrs;>
<!ELEMENT cite %Inline;> <!-- citation -->
<!ATTLIST cite %attrs;>
<!ELEMENT abbr %Inline;> <!-- abbreviation -->
<!ATTLIST abbr %attrs;>
<!ELEMENT q %Inline;> <!-- inlined quote -->
<!ATTLIST q
%attrs;
cite %URI; #IMPLIED
>
<!ELEMENT sub %Inline;> <!-- subscript -->
<!ATTLIST sub %attrs;>
<!ELEMENT sup %Inline;> <!-- superscript -->
<!ATTLIST sup %attrs;>
<!ELEMENT i %Inline;> <!-- italic font -->
<!ATTLIST i %attrs;>
<!ELEMENT b %Inline;> <!-- bold font -->
<!ATTLIST b %attrs;>
<!ELEMENT small %Inline;> <!-- smaller font -->
<!ATTLIST small %attrs;>
<!--==================== Object ======================================-->
<!--
object is used to embed objects as part of HTML pages.
param elements should precede other content. Parameters
can also be expressed as attribute/value pairs on the
object element itself when brevity is desired.
-->
<!ELEMENT object (#PCDATA | param | %block; | form | %inline; | %misc;)*>
<!ATTLIST object
%attrs;
%html5mediaevents;
data %URI; #IMPLIED
type %ContentType; #IMPLIED
height %Length; #IMPLIED
width %Length; #IMPLIED
usemap %URI; #IMPLIED
name NMTOKEN #IMPLIED
tabindex %Number; #IMPLIED
<!-- HTML 5 attributes -->
form CDATA #IMPLIED
>
引用资料
关于eclipse - Zend Studio 的 HTML5 验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5038538/
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h
我希望我的UserPrice模型的属性在它们为空或不验证数值时默认为0。这些属性是tax_rate、shipping_cost和price。classCreateUserPrices8,:scale=>2t.decimal:tax_rate,:precision=>8,:scale=>2t.decimal:shipping_cost,:precision=>8,:scale=>2endendend起初,我将所有3列的:default=>0放在表格中,但我不想要这样,因为它已经填充了字段,我想使用占位符。这是我的UserPrice模型:classUserPrice回答before_val
我有一个表单,其中有很多字段取自数组(而不是模型或对象)。我如何验证这些字段的存在?solve_problem_pathdo|f|%>... 最佳答案 创建一个简单的类来包装请求参数并使用ActiveModel::Validations。#definedsomewhere,atthesimplest:require'ostruct'classSolvetrue#youcouldevencheckthesolutionwithavalidatorvalidatedoerrors.add(:base,"WRONG!!!")unlesss
在我的Controller中,我通过以下方式在我的index方法中支持HTML和JSON:respond_todo|format|format.htmlformat.json{renderjson:@user}end在浏览器中拉起它时,它会自然地以HTML呈现。但是,当我对/user资源进行内容类型为application/json的curl调用时(因为它是索引方法),我仍然将HTML作为响应。如何获取JSON作为响应?我还需要说明什么? 最佳答案 您应该将.json附加到请求的url,提供的格式在routes.rb的路径中定义。这
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我有一些非常大的模型,我必须将它们迁移到最新版本的Rails。这些模型有相当多的验证(User有大约50个验证)。是否可以将所有这些验证移动到另一个文件中?说app/models/validations/user_validations.rb。如果可以,有人可以提供示例吗? 最佳答案 您可以为此使用关注点:#app/models/validations/user_validations.rbrequire'active_support/concern'moduleUserValidationsextendActiveSupport:
当我的预订模型通过rake任务在状态机上转换时,我试图找出如何跳过对ActiveRecord对象的特定实例的验证。我想在reservation.close时跳过所有验证!叫做。希望调用reservation.close!(:validate=>false)之类的东西。仅供引用,我们正在使用https://github.com/pluginaweek/state_machine用于状态机。这是我的预订模型的示例。classReservation["requested","negotiating","approved"])}state_machine:initial=>'requested
我有一个服务模型/表及其注册表。在表单中,我几乎拥有服务的所有字段,但我想在验证服务对象之前自动设置其中一些值。示例:--服务Controller#创建Action:defcreate@service=Service.new@service_form=ServiceFormObject.new(@service)@service_form.validate(params[:service_form_object])and@service_form.saverespond_with(@service_form,location:admin_services_path)end在验证@ser