---
title: "加载rails环境的通常办法"
author: "夜鸣猪"
date: "2012-07-16T21:19:17Z"
tags: []
categories: ["编程语言"]
slug: "rails"
draft: false
lastmod: "2012-07-16T21:19:17Z"
id: 1595692
url: "https://hlee.iteye.com/blog/1595692"
---

```ruby

#!/usr/bin/env ruby

# Set your environment here.
ENV["rails_env"] ||= "production"

require File.dirname(__FILE__) + "/../../config/environment"

puts "Rails was loaded!"


```



```ruby

rb /lib/tasks/file.rb RAILS_ENV=development

```


通常用runner

```ruby

rails runner your_script_here.rb

```