`
CaiDeHen
  • 浏览: 89946 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论
文章列表
ActiveResource allows you to easily communicate between multiple Rails applications. See how in this episode. # models/product.rb class Product < ActiveResource::Base self.site = "http://localhost:3000" end # models/post.rb class Post < ActiveRecord::Base def product ...
Action caching behaves much like page caching except it processes the controller filters. You can also make it conditional as seen in this episode. # products_controller.rb cache_sweeper :product_sweeper, :only => [:create, :update, :destroy] caches_action :index, :cache_path => :index_cache_ ...
The make_resourceful plugin is a great way to DRY up the 7 RESTful actions common in most controllers. Learn how to use it in this episode. # products_controller.rb make_resourceful do actions :all response_for :show do |format| format.html format.xml { render :xml => current_ ...
Sometimes you only want to cache a section of a page instead of the entire page. Fragment caching is the answer as shown in this episode. # products_controller.rb cache_sweeper :product_sweeper, :only => [:create, :update, :destroy] # models/product.rb class Product < ActiveRecord::Base ...
Page caching is an efficient way to cache stateless content. In this episode I will show you how to cache the dynamic javascript we created last week. # javascripts_controller.rb caches_page :dynamic_states # config/environments/development.rb config.action_controller.perform_caching = true # ...
See how to dynamically change a select menu based on another select menu using Javascript. In this episode everything is kept client side which leads to a more responsive user interface. # javascripts_controller.rb def dynamic_states @states = State.find(:all) end # application_helper.rb def ...
See how to easily generate and link to an RSS feed using new features in Rails 2.0. Watch this episode or details. # index.rss.builder xml.instruct! :xml, :version => "1.0" xml.rss :version => "2.0" do xml.channel do xml.title "Articles" xml.descrip ...
Have you ever wanted to easily log all variables? Now you can by using some advanced Ruby concepts as shown in this episode. # models/product.rb logger.debug_variables(binding) # config/initializers/logger_additions.rb logger = ActiveRecord::Base.logger def logger.debug_variables(bind) vars ...
Application configuration shouldn't be spread throughout your code base. Instead a much better place to put it is an external YAML file. See how to do that in this episode. # config/initializers/load_config.rb APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")[RAILS_ENV] # ...
In Rails 1.2 the default session store is file based. This is inefficient and difficult to maintain. In Rails 2.0 the default is now cookie based which has several benefits as you will see in this episode. in environment.rb Rails::Initializer.run do |config| config.action_controller.session = { ...
Rails 2.0 offers an extremely easy way to do HTTP basic authentication. See how in this episode. # products_controller.rb before_filter :authenticate protected def authenticate authenticate_or_request_with_http_basic do |username, password| username == "foo" && passwo ...
This more advanced episode will show you how to dynamically generate named routes by adding a method to the map object. Update: there’s now a plugin which does this called static_actions. # routes.rb ActionController::Routing::Routes.draw do |map| def map.controller_actions(controller, action ...
In this episode I will show you how to create PDF documents using the excellent PDF::Writer gem. # environment.rb require 'pdf/writer' Mime::Type.register 'application/pdf', :pdf # products_controller.rb def index @products = Product.find(:all) respond_to do |format| format.html ...
If the user has JavaScript disabled, the "Destroy" link might not work properly. In this episode I will explore a number of ways to work around this issue. <!-- projects/index.rhtml --> <ul> <% for project in @projects %> <li> <%=h project.name %> ...
The scope_out plugin will generate several helpful find methods for you automatically! It's the best way to move the find conditions into your model. Watch this episode for details. script/plugin install http://scope-out-rails.googlecode.com/svn/trunk/# models/task.rb scope_out :incomplete, :condi ...
Global site tag (gtag.js) - Google Analytics