- 浏览: 2072740 次
- 性别:
- 来自: NYC
文章分类
- 全部博客 (628)
- Linux (53)
- RubyOnRails (294)
- HTML (8)
- 手册指南 (5)
- Mysql (14)
- PHP (3)
- Rails 汇总 (13)
- 读书 (22)
- plugin 插件介绍与应用 (12)
- Flex (2)
- Ruby技巧 (7)
- Gem包介绍 (1)
- javascript Jquery ext prototype (21)
- IT生活 (6)
- 小工具 (4)
- PHP 部署 drupal (1)
- javascript Jquery sort plugin 插件 (2)
- iphone siri ios (1)
- Ruby On Rails (106)
- 编程概念 (1)
- Unit Test (4)
- Ruby 1.9 (24)
- rake (1)
- Postgresql (6)
- ruby (5)
- respond_to? (1)
- method_missing (1)
- git (8)
- Rspec (1)
- ios (1)
- jquery (1)
- Sinatra (1)
最新评论
-
dadadada2x:
user模型里加上 protected def email ...
流行的权限管理 gem devise的定制 -
Sev7en_jun:
shrekting 写道var pattern = /^(0| ...
强悍的ip格式 正则表达式验证 -
jiasanshou:
好文章!!!
RPM包rpmbuild SPEC文件深度说明 -
寻得乐中乐:
link_to其实就是个a标签,使用css控制,添加一个参数: ...
Rails在link_to中加参数 -
aiafei0001:
完全看不懂,不知所然.能表达清楚一点?
"$ is not defined" 的问题怎么办
应该是出自Netbean的generate介绍,例子还不错,有些时候能够节省时间
controller
带Modules 的例子
integration_test
介绍:
Stubs out a new integration test. Pass the name of the test, either CamelCased or under_scored, as an argument. The new test class is generated in test/integration/testname_test.rb
示例
model
migration
This will create the AddTitleBodyToPost in db/migrate/20080514090912_add_title_body_to_post.rb with this in the Up migration:
mailer
plugin
vendor/plugins/browser_filters/README
vendor/plugins/browser_filters/init.rb
vendor/plugins/browser_filters/install.rb
vendor/plugins/browser_filters/lib/browser_filters.rb
vendor/plugins/browser_filters/test/browser_filters_test.rb
vendor/plugins/browser_filters/tasks/browser_filters_tasks.rake
./script/generate plugin BrowserFilters --with-generator
creates a browser_filters generator also:
vendor/plugins/browser_filters/generators/browser_filters/browser_filters_generator.rb
vendor/plugins/browser_filters/generators/browser_filters/USAGE
vendor/plugins/browser_filters/generators/browser_filters/templates/
scaffold
session_migration
metal
Cast some metal!
observer
Observer: app/models/account_observer.rb
Test: test/unit/account_observer_test.rb
resource
helper
Helper: app/helpers/credit_card_helper.rb
Test: test/unit/helpers/credit_card_helper_test.rb
Modules
Helper: app/helpers/admin/credit_card_helper.rb
Test: test/unit/helpers/admin/credit_card_helper_test.rb
performance_test
controller
引用
Stubs out a new controller and its views. Pass the controller name, either CamelCased or under_scored, and a list of views as arguments.
To create a controller within a module, specify the controller name as a path like parent_module/controller_name.
This generates a controller class in app/controllers, view templates in app/views/controller_name, a helper class in app/helpers, a functional test suite in test/functional and a helper test suite in test/unit/helpers.
To create a controller within a module, specify the controller name as a path like parent_module/controller_name.
This generates a controller class in app/controllers, view templates in app/views/controller_name, a helper class in app/helpers, a functional test suite in test/functional and a helper test suite in test/unit/helpers.
./script/generate controller CreditCard open debit credit #Credit card controller with URLs like /credit_card/debit. close
引用
Controller: app/controllers/credit_card_controller.rb
Functional Test: test/functional/credit_card_controller_test.rb
Views: app/views/credit_card/debit.html.erb [...]
Helper: app/helpers/credit_card_helper.rb
Helper Test: test/unit/helpers/credit_card_helper_test.rb
Functional Test: test/functional/credit_card_controller_test.rb
Views: app/views/credit_card/debit.html.erb [...]
Helper: app/helpers/credit_card_helper.rb
Helper Test: test/unit/helpers/credit_card_helper_test.rb
带Modules 的例子
./script/generate controller 'admin/credit_card' suspend late_fee #Credit card admin controller with URLs /admin/credit_card/suspend.
引用
Controller: app/controllers/admin/credit_card_controller.rb
Functional Test: test/functional/admin/credit_card_controller_test.rb
Views: app/views/admin/credit_card/debit.html.erb [...]
Helper: app/helpers/admin/credit_card_helper.rb
Helper Test: test/unit/helpers/admin/credit_card_helper_test.rb
Functional Test: test/functional/admin/credit_card_controller_test.rb
Views: app/views/admin/credit_card/debit.html.erb [...]
Helper: app/helpers/admin/credit_card_helper.rb
Helper Test: test/unit/helpers/admin/credit_card_helper_test.rb
integration_test
介绍:
引用
Stubs out a new integration test. Pass the name of the test, either CamelCased or under_scored, as an argument. The new test class is generated in test/integration/testname_test.rb
示例
./script/generate integration_test GeneralStories #creates a GeneralStories integration test in test/integration/general_stories_test.rb
model
引用
Stubs out a new model. Pass the model name, either CamelCased or under_scored, and an optional list of attribute pairs as arguments.
Attribute pairs are column_name:sql_type arguments specifying the model's attributes. Timestamps are added by default, so you don't have to specify them by hand as created_at:datetime updated_at:datetime.
You don't have to think up every attribute up front, but it helps to sketch out a few so you can start working with the model immediately.
This generates a model class in app/models, a unit test in test/unit, a test fixture in test/fixtures/singular_name.yml, and a migration in db/migrate.
Attribute pairs are column_name:sql_type arguments specifying the model's attributes. Timestamps are added by default, so you don't have to specify them by hand as created_at:datetime updated_at:datetime.
You don't have to think up every attribute up front, but it helps to sketch out a few so you can start working with the model immediately.
This generates a model class in app/models, a unit test in test/unit, a test fixture in test/fixtures/singular_name.yml, and a migration in db/migrate.
./script/generate model account #creates an Account model, test, fixture, and migration:
引用
Model: app/models/account.rb
Test: test/unit/account_test.rb
Fixtures: test/fixtures/accounts.yml
Migration: db/migrate/XXX_add_accounts.rb
Test: test/unit/account_test.rb
Fixtures: test/fixtures/accounts.yml
Migration: db/migrate/XXX_add_accounts.rb
./script/generate model post title:string body:text published:boolean #creates a Post model with a string title, text body, and published flag.
migration
引用
Stubs out a new database migration. Pass the migration name, either CamelCased or under_scored, and an optional list of attribute pairs as arguments.
A migration class is generated in db/migrate prefixed by a timestamp of the current date and time.
You can name your migration in either of these formats to generate add/remove column lines from supplied attributes: AddColumnsToTable or RemoveColumnsFromTable
A migration class is generated in db/migrate prefixed by a timestamp of the current date and time.
You can name your migration in either of these formats to generate add/remove column lines from supplied attributes: AddColumnsToTable or RemoveColumnsFromTable
./script/generate migration AddSslFlag #If the current date is May 14, 2008 and the current time 09:09:12, this creates the AddSslFlag migration db/migrate/20080514090912_add_ssl_flag.rb ./script/generate migration AddTitleBodyToPost title:string body:text published:boolean`
This will create the AddTitleBodyToPost in db/migrate/20080514090912_add_title_body_to_post.rb with this in the Up migration:
引用
add_column :posts, :title, :string
add_column :posts, :body, :text
add_column :posts, :published, :boolean
And this in the Down migration:
remove_column :posts, :published
remove_column :posts, :body
remove_column :posts, :title
add_column :posts, :body, :text
add_column :posts, :published, :boolean
And this in the Down migration:
remove_column :posts, :published
remove_column :posts, :body
remove_column :posts, :title
mailer
引用
Stubs out a new mailer and its views. Pass the mailer name, either CamelCased or under_scored, and an optional list of emails as arguments.
This generates a mailer class in app/models, view templates in app/views/mailer_name, a unit test in test/unit, and fixtures in test/fixtures.
This generates a mailer class in app/models, view templates in app/views/mailer_name, a unit test in test/unit, and fixtures in test/fixtures.
./script/generate mailer Notifications signup forgot_password invoice #creates a Notifications mailer class, views, test, and fixtures:
引用
Mailer: app/models/notifications.rb
Views: app/views/notifications/signup.erb [...]
Test: test/unit/test/unit/notifications_test.rb
Fixtures: test/fixtures/notifications/signup [...]
Views: app/views/notifications/signup.erb [...]
Test: test/unit/test/unit/notifications_test.rb
Fixtures: test/fixtures/notifications/signup [...]
plugin
引用
Stubs out a new plugin. Pass the plugin name, either CamelCased or under_scored, as an argument. Pass –with-generator to add an example generator also.
This creates a plugin in vendor/plugins including an init.rb and README as well as standard lib, task, and test directories.
This creates a plugin in vendor/plugins including an init.rb and README as well as standard lib, task, and test directories.
./script/generate plugin BrowserFilters #creates a standard browser_filters plugin:
vendor/plugins/browser_filters/README
vendor/plugins/browser_filters/init.rb
vendor/plugins/browser_filters/install.rb
vendor/plugins/browser_filters/lib/browser_filters.rb
vendor/plugins/browser_filters/test/browser_filters_test.rb
vendor/plugins/browser_filters/tasks/browser_filters_tasks.rake
./script/generate plugin BrowserFilters --with-generator
creates a browser_filters generator also:
vendor/plugins/browser_filters/generators/browser_filters/browser_filters_generator.rb
vendor/plugins/browser_filters/generators/browser_filters/USAGE
vendor/plugins/browser_filters/generators/browser_filters/templates/
scaffold
引用
Scaffolds an entire resource, from model and migration to controller and views, along with a full test suite. The resource is ready to use as a starting point for your RESTful, resource-oriented application.
Pass the name of the model (in singular form), either CamelCased or under_scored, as the first argument, and an optional list of attribute pairs.
Attribute pairs are column_name:sql_type arguments specifying the model's attributes. Timestamps are added by default, so you don't have to specify them by hand as created_at:datetime updated_at:datetime.
You don't have to think up every attribute up front, but it helps to sketch out a few so you can start working with the resource immediately.
For example, scaffold post title:string body:text published:boolean gives you a model with those three attributes, a controller that handles the create/show/update/destroy, forms to create and edit your posts, and an index that lists them all, as well as a map.resources :posts declaration in config/routes.rb.
If you want to remove all the generated files, run script/destroy scaffold ModelName.
Pass the name of the model (in singular form), either CamelCased or under_scored, as the first argument, and an optional list of attribute pairs.
Attribute pairs are column_name:sql_type arguments specifying the model's attributes. Timestamps are added by default, so you don't have to specify them by hand as created_at:datetime updated_at:datetime.
You don't have to think up every attribute up front, but it helps to sketch out a few so you can start working with the resource immediately.
For example, scaffold post title:string body:text published:boolean gives you a model with those three attributes, a controller that handles the create/show/update/destroy, forms to create and edit your posts, and an index that lists them all, as well as a map.resources :posts declaration in config/routes.rb.
If you want to remove all the generated files, run script/destroy scaffold ModelName.
./script/generate scaffold post ./script/generate scaffold post title:string body:text published:boolean ./script/generate scaffold purchase order_id:integer amount:decimal
session_migration
引用
Creates a migration to add the sessions table used by the Active Record session store. Pass the migration name, either CamelCased or under_scored, as an argument.
./script/generate session_migration CreateSessionTable #With 4 existing migrations, this creates the AddSessionTable migration in db/migrate/005_add_session_table.rb
metal
Cast some metal!
./script/generate metal poller #This will create: Metal: app/metal/poller.rb
observer
Stubs out a new observer. Pass the observer name, either CamelCased or under_scored, as an argument. The generator creates an observer class in app/models and a unit test in test/unit.
./script/generate observer Account #creates an Account observer and unit test:
Observer: app/models/account_observer.rb
Test: test/unit/account_observer_test.rb
resource
引用
Stubs out a new resource including an empty model and controller suitable for a restful, resource-oriented application. Pass the singular model name, either CamelCased or under_scored, as the first argument, and an optional list of attribute pairs.
Attribute pairs are column_name:sql_type arguments specifying the model's attributes. Timestamps are added by default, so you don't have to specify them by hand as created_at:datetime updated_at:datetime.
You don't have to think up every attribute up front, but it helps to sketch out a few so you can start working with the resource immediately.
This creates a model, controller, helper, tests and fixtures for all of them, and the corresponding map.resources declaration in config/routes.rb
Unlike the scaffold generator, the resource generator does not create views or add any methods to the generated controller.
Attribute pairs are column_name:sql_type arguments specifying the model's attributes. Timestamps are added by default, so you don't have to specify them by hand as created_at:datetime updated_at:datetime.
You don't have to think up every attribute up front, but it helps to sketch out a few so you can start working with the resource immediately.
This creates a model, controller, helper, tests and fixtures for all of them, and the corresponding map.resources declaration in config/routes.rb
Unlike the scaffold generator, the resource generator does not create views or add any methods to the generated controller.
./script/generate resource post # no attributes ./script/generate resource post title:string body:text published:boolean ./script/generate resource purchase order_id:integer amount:decimal
helper
引用
Stubs out a new helper. Pass the helper name, either CamelCased or under_scored.
To create a helper within a module, specify the helper name as a path like parent_module/helper_name.
This generates a helper class in app/helpers and a helper test suite in test/unit/helpers.
To create a helper within a module, specify the helper name as a path like parent_module/helper_name.
This generates a helper class in app/helpers and a helper test suite in test/unit/helpers.
./script/generate helper CreditCard #Credit card helper.
Helper: app/helpers/credit_card_helper.rb
Test: test/unit/helpers/credit_card_helper_test.rb
Modules
./script/generate helper 'admin/credit_card' #Credit card admin helper.
Helper: app/helpers/admin/credit_card_helper.rb
Test: test/unit/helpers/admin/credit_card_helper_test.rb
performance_test
引用
Stubs out a new performance test. Pass the name of the test, either CamelCased or under_scored, as an argument. The new test class is generated in test/performance/testname_test.rb
./script/generate performance_test GeneralStories #creates a GeneralStories performance test intest/performance/general_stories_test.rb
发表评论
-
Destroying a Postgres DB on Heroku
2013-04-24 10:58 928heroku pg:reset DATABASE -
VIM ctags setup ack
2012-04-17 22:13 3255reference ctags --extra=+f --e ... -
alias_method_chain方法在3.1以后的替代使用方式
2012-02-04 02:14 3288alias_method_chain() 是rails里的一个 ... -
一些快速解决的问题
2012-01-19 12:35 1470问题如下: 引用Could not open library ... -
API service 安全问题
2011-12-04 08:47 1380这是一个长期关注的课题 rest api Service的 ... -
Module方法调用好不好
2011-11-20 01:58 1344以前说,用module给class加singleton方法,和 ... -
一个ajax和rails交互的例子
2011-11-19 01:53 1903首先,这里用了一个,query信息解析的包,如下 https: ... -
Rails 返回hash给javascript
2011-11-19 01:43 2272这是一个特别的,不太正统的需求, 因为,大部分时候,ajax的 ... -
关于Rubymine
2011-11-18 23:21 2263开个帖子收集有关使用上的问题 前一段时间,看到半价就买了。想 ... -
ruby中和javascript中,动态方法的创建
2011-11-18 21:01 1234class Klass def hello(*args) ... -
textmate快捷键 汇总
2011-11-16 07:20 8138TextMate 列编辑模式 按住 Alt 键,用鼠标选择要 ... -
Ruby面试系列六,面试继续面试
2011-11-15 05:55 2018刚才受到打击了,充分报漏了自己基础不扎实,不肯向虎炮等兄弟学习 ... -
说说sharding
2011-11-13 00:53 1481这个东西一面试就有人 ... -
rails面试碎碎念
2011-11-12 23:51 1939面试继续面试 又有问ru ... -
最通常的git push reject 和non-fast forward是因为
2011-11-12 23:29 17209git push To git@github.com:use ... -
Rails 自身的many to many关系 self has_many
2011-11-12 01:43 2732简单点的 #注意外键在person上people: id ... -
Rails 3下的 in place editor edit in place
2011-11-12 01:20 945第一个版本 http://code.google.com/p ... -
Heroku 的诡异问题集合
2011-11-11 07:22 1692开个Post记录,在用heroku过程中的一些诡异问题和要注意 ... -
SCSS 和 SASS 和 HAML 和CoffeeScript
2011-11-07 07:52 12952Asset Pipeline 提供了内建 ... -
Invalid gemspec because of the date format in specification
2011-11-07 02:14 2115又是这个date format的错误。 上次出错忘了,记录下 ...
相关推荐
2. 创建资源:使用`rails generate controller Posts`生成控制器,再用`rails generate scaffold Post title:string content:text`生成模型和相关的控制器、视图及路由。 3. 迁移数据库:编写迁移文件,更新数据库表...
ruby rails demo, rails 简单demo。 ...(2)安装Rails3 gem install rails (3)安装sqlite3 gem install ...rails generate scaffold Post name:string title:string content:text rake routes 显示路由config/routes.rb
1. **生成资源(Generating Resources)**:使用`rails generate`命令可以快速创建模型、控制器、视图等文件,如`rails generate scaffold Post title:string content:text`会生成一个名为Post的资源,包含相关的...
接着,使用Rails的生成器创建控制器、模型和视图,如`rails generate controller`或`rails generate model`。然后,配置数据库连接,编写数据库迁移(migrations)以定义数据表结构,执行`rake db:migrate`来应用...
`rails generate migration AddColumnToBooks column:type`会生成一个新的迁移文件,然后通过`rails db:migrate`执行迁移,更新数据库。 7. **路由(Routing)** Rails的路由系统将URL映射到控制器的动作上,定义...
8. **生成器和迁移**:Rails提供了一些命令行工具,如`rails generate`和`rails db:migrate`,用于快速生成模型、控制器、迁移等,并执行数据库迁移。 9. **测试**:Rails鼓励TDD(测试驱动开发),`spec`目录包含...
installrails generate devise user ######安装CanCan: gem 'cancan'bundle install rails generate cancan : ability rails generate model role name : string rails generate migration UsersHaveAndBelongToMa
此外,`rails generate scaffold`命令也变得更加灵活,可以自定义模板。 4. Rails 4.0: Rails 4带来了大量的改变和优化。最显著的是加入了Strong Parameters,提高了安全性,避免了Mass Assignment漏洞。另外,它...
rails generate scaffold person name:string bio:text birthday:date ``` - **模型创建与删除**: ```bash rails generate model article rails destroy model article ``` - **控制器创建**: ```bash ...
rails generate go_on_rails:app my_go_app ``` 这将在Rails项目的`lib/my_go_app`目录下创建一个新的Go应用结构。 ### 4. 集成Go API `GoOnRails`会生成一个基础的Go API服务器,你可以在此基础上编写业务逻辑。...
7. **Rails 命令行工具和 Rake 任务**: Rails 提供了一系列命令行工具,如 `rails server`、`rails generate` 和 `rails dbconsole`,帮助开发者快速启动、生成代码和操作数据库。Rake 是一个构建工具,用于执行任务...
rails generate model City province_id:integer name:string rails generate model District city_id:integer name:string ``` 然后,通过运行`rails db:migrate`来执行数据库迁移。 在模型定义完成后,作者会...
电源类型 Platanus 团队...安装添加到您的 Gemfile: gem "power-types" bundle install电源类型服务为了生成服务,我们使用: $ rails generate service MyService foo bar这将创建 MyService 类,继承自基础服务类:
接着,你可以通过Rails的generate命令来触发CRUD Generator 2,例如: ```bash rails generate crud_generator2 ModelName ``` 这里的`ModelName`是你需要创建的模型名称。这个命令将会生成相应的模型文件、控制器...
Rails提供了一系列内置的命令行工具,如`rails new`创建新应用,`rails generate`生成模型、控制器、迁移等。这些发电机能快速生成基本结构,加速开发过程。 11. **Scaffolding** Scaffolding是Rails提供的一种...
- 示例:通过`rails generate scaffold Topic title:string description:text`创建一个Topic模型及其关联的CRUD操作。 - **整合Bootstrap与版型设置**:介绍如何将Bootstrap框架集成到Rails应用中,并设置基础版型...
Rails提供了许多命令行工具,如`rails generate`,可以自动生成模型、控制器、迁移等,大大减少了手动编码的工作量。 六、ActiveRecord和数据库 ActiveRecord是Rails中的ORM(对象关系映射)库,它自动处理数据库...
通过`rails generate`命令,可以自动生成控制器、模型、视图等相关文件,例如创建一个名为`autoweb`的应用,只需执行`rails generate controller Autoweb`,Rails会自动创建相关文件,开发者只需要填充具体业务逻辑...
《Rails101_by_rails4.0》是一本专注于Rails 4.0.0版本和Ruby 2.0.0版本的自学教程书籍,它定位于中文读者,旨在成为学习Rails框架的参考教材。Rails(Ruby on Rails)是一个采用Ruby语言编写的开源Web应用框架,它...
Ruby on Rails,通常简称为Rails,是一个基于Ruby编程语言的开源Web应用框架,遵循MVC(Model-View-Controller)架构模式。这个“Rails项目源代码”是一个使用Rails构建的图片分享网站的完整源代码,它揭示了如何...