摘要:
1、Rails的国际化根据特定的locale信息,提取相应的内容通过config/environment.rb,指定应用的转换文件 config.i18n.load_path +=Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')] #指定搜索的文件类型 config.i18n.default_locale =:zh #指定默认的文件在config/locales中创建zh文件,提供转换的方式2、validates用于校验validates_presence_of 确认属性值不为nil也不为空va 阅读全文
posted @ 2013-08-03 23:31
wangyuyu
阅读(581)
评论(0)
推荐(0)
摘要:
strip_tags(html)Strips all HTML tags from the html, including comments. This usesthe html-scanner tokenizer and so its HTML parsing ability is limited bythat of html-scanner.Examples strip_tags("Strip these tags!") # => Strip these tags! strip_tags("Bold no more! See more here...&q 阅读全文
posted @ 2013-08-03 23:30
wangyuyu
阅读(803)
评论(0)
推荐(0)
摘要:
一般来说,通常使用input的field都会做一些filter的动作,避免被不怀好意之徒塞一些危险的HTML code(script等)进去搞破坏。在ROR中,我们在前面加一个h()(一般不用括号?不容易看到?)即可,h在ROR中起什么作用呢?他是html_escape的alias(别名),他会将所有的""变成<;,>,比如:js 代码 会变成: <script>alert('a');</script>这样就完全做不了乱了。因为所有的tag都被搞掉了。这样太严格了,有时候我们需要 阅读全文
posted @ 2013-08-03 22:41
wangyuyu
阅读(873)
评论(0)
推荐(0)
摘要:
image_tag(source, options={}) LinkReturns an HTML image tag for thesource. The source can be a full path or a file.OptionsYou can add HTML attributes using theoptions. The options supports three additionalkeys for convenience and conformance::alt - If no alt text is given, the file name part of thes 阅读全文
posted @ 2013-08-03 22:35
wangyuyu
阅读(1191)
评论(0)
推荐(0)
摘要:
render 先上点搜集的常用方式[ruby] view plaincopyprint?render :action => "long_goal", :layout => "spectacular" render :partial => "person", :locals => { :name => "david" } render :template => "weblog/show", :locals => {:customer => Custo 阅读全文
posted @ 2013-08-03 22:32
wangyuyu
阅读(12347)
评论(0)
推荐(0)
摘要:
x.指定端口启动rails项目ruby script/server webrick -p 3000------------------------------------------------- 0.创建一个项目 rials demoshop ------------------------------------------------- 1.用脚手架创建产品(控制 模型 显示 数据) script/generate scaffold product title:string description:text image_url:string ----------------------- 阅读全文
posted @ 2013-08-03 22:20
wangyuyu
阅读(848)
评论(0)
推荐(0)
摘要:
自己很初级,初级的不能再初级,所以初次接触rails的时候,对于里面的create,new,build等方法不是很了解,用的很混乱,导致经常出现不必要的bug,很苦恼,决定,总结一下,结合网上已有资源,深入理解下 向数据库插记录时经常会用到new, build, create。这三个方法很容易混淆 save:rails中的save其实是create_or_update,新建或修改记录!不一定是新建,切记 new :只是在内存中新建一个对象,操作数据库要调用save方法。 create = new + 执行sql。 build:与new基本相同,多用于一对多情况下。还有一个不同请看使用示例 .. 阅读全文
posted @ 2013-08-03 21:50
wangyuyu
阅读(6069)
评论(0)
推荐(0)

浙公网安备 33010602011771号