`
CaiDeHen
  • 浏览: 94257 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论
文章列表
If you need to create an advanced search with a lot of fields, it may not be ideal to use a GET request as I showed in episode 37. In this episode I will show you how to handle this by creating a Search resource. <!-- views/searches/new.html.erb --> <% form_for @search do |f| %> <p ...
In Rails 2.1 we now have the ability to set gem dependencies. Now it's easier than ever to specify which ruby gems our rails app relies on. # config/environment.rb config.gem "RedCloth", :version => ">= 3.0.4", :source => "http://code.whytheluckystiff.net/" co ...
Rails 2.1 keeps track of the changes you make to a model's attributes. It also allows you to see what the previous value was. But watch out for the gotcha! See this episode for details. # config/initializers/active_record_settings.rb ActiveRecord::Base.partial_updates = true # change tracking met ...
The named_scope method in Rails 2.1 makes performing finds on models very elegant and convenient. See how in this episode. # models/product.rb class Product < ActiveRecord::Base belongs_to :category named_scope :cheap, :conditions => { :price => 0..5 } named_scope :recent, lambda { ...
Migrations now have a timestamp as their version number in Rails 2.1. In this episode I will explain this change as well as show you some other cool additions. # in a migration file def self.up change_table :products do |t| t.rename :released_on, :released_at t.change :description, :tex ...
In the past, time zones have been very difficult to work with, but no longer! Rails 2.1 brings with it great time zone support as you can see in this episode. rake time:zones:local # config/environment.rb config.time_zone = "Pacific Time (US & Canada)" # controllers/application. ...
If you're running a production site, it's a good idea to record all exceptions which occur. See how to set up a notification system which does that in this episode. Note: I forgot to mention, the exception_logger plugin requires will_paginate, so make sure you have that installed either through a plu ...
Sometimes you need to display an administrative announcement to every page on the site and give the users the ability to hide the announcement. See how in this episode. script/generate scaffold announcement message:text starts_at:datetime ends_at:datetime script/generate controller javascripts &l ...
Usually a select menu is used for setting a belongs_to association, but in this episode I will show you how to use a text field with auto completion. script/plugin install auto_complete # product.rb def category_name category.name if category end def category_name=(name) self.category = ...
If you have complex view logic, this can easily lead to helper methods which call each other. See how to refactor this out into another object in this episode. # application_helper.rb def render_stars(rating) StarsRenderer.new(rating, self).render_stars end # helpers/stars_renderer.rb class ...
Tip #1: Whitespace in ERB Templates Use a dash at the beginning and end of an ERB tag to remove the white space around it. <div id="products"> <%- for product in @products -%> <h3><%=h product.name %></h3> <%- end -%> </div> Tip #2: co ...
How do you handle partials which have differences depending on the action which is rendering them? Here's three suggestions for this problem. <!-- index.html.erb --> <% for article in @articles %> <% render :layout => 'article', :object => article do %> <p><% ...
You can use profiling to determine where the performance bottlenecks are in specific Rails actions. Watch this episode for details. # config/environments/staging.rb config.cache_classes = true config.action_controller.consider_all_requests_local = false config.action_controller.perform_caching ...
Git has been getting a lot of buzz lately, and for good reason. It's an excellent SCM which in many ways is more simple and powerful than subversion. See how to set up a Rails project with Git in this episode. # commands git init git status git add . git commit -a touch tmp/.gitignore log/.gitig ...
See how to handle authentication and custom actions using ActiveResource in this episode. # models/product.rb (in blog app) class Product < ActiveResource::Base self.site = "http://admin:secret@localhost:3000" end # script/console (in blog app) Product.find(:all) # GET products. ...
Global site tag (gtag.js) - Google Analytics