- 浏览: 94249 次
- 性别:
- 来自: 成都
最新评论
-
xylffxyfpp:
应该改成慎用each
万恶的"delete",慎用数组的delete -
xylffxyfpp:
a = [1,2,3,4,5,6]
a.each do ...
万恶的"delete",慎用数组的delete -
CaiDeHen:
受教了,我也不知道当时为什么会在这个地方这样子用。其他地方也是 ...
万恶的"delete",慎用数组的delete -
wosmvp:
感觉太乱了为什么不在User模型中来个 named_scope ...
万恶的"delete",慎用数组的delete -
jiachengxi38:
不知道楼主这样的逻辑想法从何而来,权限访问的思想好像在lZ这里 ...
万恶的"delete",慎用数组的delete
文章列表
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
...
- 2008-12-10 14:58
- 浏览 646
- 评论(0)
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_ ...
- 2008-12-10 14:56
- 浏览 634
- 评论(0)
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_ ...
- 2008-12-10 14:55
- 浏览 760
- 评论(0)
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
...
- 2008-12-10 14:39
- 浏览 742
- 评论(0)
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
# ...
- 2008-12-10 14:35
- 浏览 513
- 评论(0)
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 ...
- 2008-12-10 14:33
- 浏览 683
- 评论(0)
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 ...
- 2008-12-10 12:02
- 浏览 674
- 评论(0)
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 ...
- 2008-12-10 11:59
- 浏览 792
- 评论(0)
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]
# ...
- 2008-12-09 21:22
- 浏览 794
- 评论(0)
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 = {
...
- 2008-12-09 21:11
- 浏览 737
- 评论(0)
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 ...
- 2008-12-09 21:09
- 浏览 921
- 评论(0)
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 ...
- 2008-12-09 20:20
- 浏览 667
- 评论(0)
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
...
- 2008-12-09 20:17
- 浏览 702
- 评论(0)
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 %>
...
- 2008-12-09 20:05
- 浏览 699
- 评论(0)
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 ...
- 2008-12-09 20:03
- 浏览 710
- 评论(0)