`
peryt
  • 浏览: 54356 次
  • 来自: ...
最近访客 更多访客>>
社区版块
存档分类
最新评论
  • waiting: 既然都指定了dataType为'script'那就不必特别在b ...
    jQuery
文章列表
1. for a string class:   s = "foobar"  # this a literal constructor for strings using double quotes s.class   => String   we see here that string respond to the method "class", and return the class it belong to.   2. instead of using literal constructor, we can use named ...
there is one note about the element order in hashes: Ruby 1.9 actually guarantees that hashes keep their elements in the same order entered, but it would be unwise ever to count on a particular ordering.    ==================================================   let's see this method:   stylesh ...
inspect is a method that will return a string with literal representation of the object it is called on.   puts (1..5).to_a.inspect => [1, 2, 3, 4, 5]   puts :name.inspect => :name   by the way, using inspect to print an object is so common that there is a shortcut for it, the p functio ...
Do you know why rails like using symbol instead of string as key for hash? the answer is, when comparing symbol, it find the symbol object_id, then find the symbol, Because there is only one copy of the same symbol in the memory in ruby. when comparing string, it has to compare the characters in ...
国际化(i18n)是rails2.2引入的新的特征,这一节我们演示如何使用他使你的网站自动具有多种语言。 当用户注册的时候,我们想使他们可以选择使用哪种语言,在此,我们让他们可以选择english 还是 wookieespeak。 我们使用Restful A ...
在第43个railscast, 我们介绍了如何通过ajax来更新页面的多个元素,我们使用了Prototype libraries 和 form_remote_for 来提交AJAX请求, 和使用RJS模板生成javascript作为response,返回给浏览器,更新这些元素。 在本节中,我们将使用jQuery, 而不是Prototype 和 RJS, 来做同样的事情。 既然使用jQuery,我们就不能够再使用rails提供的RJS或者任何的辅助方法如form_remote_for了。 如果我们仍然想使用RJS,那么就要安装一个plugin叫做jRails的。 这个plugin将会rewr ...
我们首先生成一个新的rails程序 rails bookshop 然后安装scaffolding plugin, (因为这个模块被rails2.0赶出去,变成plugin了) C:\workspace2\bookshop>ruby script/plugin install scaffolding 然后运行 ruby script/generate scaffold product title:string description:string image_url:string 这样就生成了controller and model and view 而且还有migration。 ok ...
RJS使得我们可以很容易的实现AJAX效果,但是bug还是会发生。 在这一节,我们展示如何在客户端和服务器端调试RJS错误。 上一节中,我们演示了让用户可以通过AJAX添加reviews,但是这个功能现在坏掉了,当用户点添加评论的按钮的时候,什么也没有发生,也就是说AJAX出错了,但是错在哪里呢?看不出来,没有任何线索,AJAX的错误比普通的错误更难以找到问题根源。是我们的请求根本没有送到服务器端,还是服务器端处理的时候还是返回的时候出错了?这种bug很难追踪,因为浏览器并不提示任何错误信息,所以我们不知道从哪一行代码开始查找错误。 跟踪调用 首先,我们应该去看看页面的源代码,注意< ...
1. 这篇文章还是关于AJAX的,算是一个复习把。 这里,我们将要加入一些AJAX功能到一个站点,其中将使用RJS模板。使用RJS是模板是实现AJAX效果的最简单的方法,特别是你需要更新一个页面的多个元素的时候。 在我们的产品页面 ...
1. 在上一篇文章中,我们介绍了如何使用edit field来编辑日期和时间,而不是用很多的dropdown menus. 那些日期和时间首先被用文本输入到一个编辑框中,然后被rails用自带的日期解析函数解析成日期和时间存储到数据库中。 例如: ...
一般来说,在一个方法内,你可以运用循环。 但是,ruby允许通过循环来批量定义方法 例如如下的代码 ROLES.each do |role|   define_method “#{role}?” do     self.role == role   end end
ruby test/unit/abcd.rb --name test_the_1st_method 也就是运用name参数,指定只运行其中一个method
1. 书籍: rails 圣经: Agile Web Development with Rails Ruby 圣经: programming ruby Rails Recipes:  rails 菜单,介绍几十个最常用的rails的偏方,涉及View, AJAX, 数据库,email, 是实用主义至上的书籍,相信每个rails项目都会用到其中的偏方。 有这三本书足以。 2. 常用的plugin 和 gem 2.1 Capistrano:  让部署成为乐趣 2.2 Streamlined: 一分钟做好网站后台的好工具。 2.3 RedCloth: 做Rich Content 的好东西 2. ...
例如在一个项目中,多处用到了搜索数据库中多个column的功能: class Post < ActiveRecord::Base has_many :comments def self.search(query, fields, options = {}) find :all, options.merge(:conditions => [[fields].flatten.map {|f| "LOWER(#{f}) LIKE :query"}.join (' OR '), {:query => "%#{query.to_s.down ...
rails and ajax render:update do |page| page.replace_html 'user_list', :paitial => 'user', :collection => @users page.visual_effect :highlight, 'user_list' end render:update 生成了一个javascript generator,也就是上面的page, 这个generator提供了很多方法,可以用来 ...
Global site tag (gtag.js) - Google Analytics