SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
Rails 3 app auto-generator
            Tse-Ching Ho
      2010/08/17 Ruby-Tuesday | ruby.tw
It’s bored to always write
      the same codes.
Who needs auto generator?
NO, Rails Newbies!!
Before you do it,

You must understand what you are doing.

You should play on local branch (git/mercurial).

You should know each pieces of codes (Don’t generate trash).

You need consistency between projects.

You want be a time saver (Stop copy, paste and verify).

You type codes as slow as me :(
What should we do?
Modulate your codes


Maintainability is a critical thing for long life projects.

Reusability is valuable for programmers.

Modules are everywhere in rails 3. Use it!
Gemify your modules
Be a ruby gem producer
http://railscasts.com/episodes/218-making-generators-in-rails-3

jeweler --rspec --gemcutter my_awesome_gem

bundle gem my_awesome_gem

   create my_awesome_gem/Gemfile
   create my_awesome_gem/Rakefile
   create my_awesome_gem/.gitignore
   create my_awesome_gem/my_awesome_gem.gemspec
   create my_awesome_gem/lib/my_awesome_gem.rb
   create my_awesome_gem/lib/my_awesome_gem/version.rb

   rake build
   rake install
   rake push
Update to Rails 3

Be familiar with APIs of thor and rails 3 generator
  gsub_file 'public/stylesheets/blueprint/screen.css', /src/grid.png/, 'grid.png'

  inject_into_file 'config/application.rb', "n   config.middleware.use Rack::Tidyn", :before => " end
  nendn"


Keep updated by force/skip overwrite option
  rails generate responders:install -f
Live Demo
Issues
Bundler
Gemfile.lock should always keep updated in generators.

  gem 'simple_form'
  run 'bundle install'
  run 'bundle update'
  generate 'simple_form:install', '-s'

Use gems, don’t use git branch.

You should commit Gemfile.lock if you need consistency
between development and production environment.
JQuery

get 'http://github.com/rails/jquery-ujs/raw/master/src/rails.js', 'public/
javascripts/rails.js'

inject_into_file 'config/application.rb', "
config.action_view.javascript_expansions[:defaults] = %w(jquery jquery-ui rails)
n", :after => "# config.action_view.javascript_expansions[:defaults] = %w(jquery
rails)n", :verbose => false

jqueryui.com only keeps the latest one zip file!

   http://jqueryui.com/download/jquery-ui-1.8.4.custom.zip
Customized templates
Rails.root/lib/templates/erb/scaffold/index.html.erb

config.generators.scaffold_controller = :responders_controller

config.generators do |g|
  g.orm              :active_record
  g.template_engine :erb
  g.integration_tool :rspec
  g.test_framework :rspec
  g.scaffold         :stylesheets => false
end
Migration files
migration_template 'create_roles.rb', 'db/migrate/create_roles.rb'

# Implement the required interface for Rails::Generators::Migration.
def self.next_migration_number(dirname) #:nodoc:
  @next_migration_number = if @next_migration_number
      (@next_migration_number.to_i + 1).to_s
  elsif ActiveRecord::Base.timestamped_migrations
      Time.now.utc.strftime("%Y%m%d%H%M%S")
  else
      "%.3d" % (current_migration_number(dirname) + 1)
  end
end
def migration_template(source, destination=nil, config={})
  super
rescue Rails::Generators::Error => e
  puts e
end
What else?

File.exist?

File path

  source_root

  destination_root

  Rails.root

Customized configuration files (config/xxx.rb)
Make every practices as
      generator!
Q&A
About me


       Tse-Ching Ho (http://github.com/tsechingho)

Use Rails 2 since 2008

Senior R&D programmer in techbang.tw (T     ) now
- END -

Weitere ähnliche Inhalte

Was ist angesagt?

Up & running with ECMAScript6
Up & running with ECMAScript6Up & running with ECMAScript6
Up & running with ECMAScript6Nir Kaufman
 
Ansible -new kid in configuration management world
Ansible -new kid in configuration management worldAnsible -new kid in configuration management world
Ansible -new kid in configuration management worldMaciej Sawicki
 
MVC-RS par Grégoire Lhotelier
MVC-RS par Grégoire LhotelierMVC-RS par Grégoire Lhotelier
MVC-RS par Grégoire LhotelierCocoaHeads France
 
javascript for backend developers
javascript for backend developersjavascript for backend developers
javascript for backend developersThéodore Biadala
 
AngularJS performance & production tips
AngularJS performance & production tipsAngularJS performance & production tips
AngularJS performance & production tipsNir Kaufman
 
A little respect for MVC part 1 par Gegoire Lhotellier
A little respect for MVC part 1 par Gegoire LhotellierA little respect for MVC part 1 par Gegoire Lhotellier
A little respect for MVC part 1 par Gegoire LhotellierCocoaHeads France
 
What's New in JHipsterLand - Devoxx Poland 2017
What's New in JHipsterLand - Devoxx Poland 2017What's New in JHipsterLand - Devoxx Poland 2017
What's New in JHipsterLand - Devoxx Poland 2017Matt Raible
 
Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Matt Raible
 
Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love RubyBen Scheirman
 
Performance monitoring measurement angualrjs single page apps with phantomas
Performance monitoring measurement angualrjs single page apps with phantomasPerformance monitoring measurement angualrjs single page apps with phantomas
Performance monitoring measurement angualrjs single page apps with phantomasDavid Amend
 
React‌ برای دولوپرها
React‌ برای دولوپرهاReact‌ برای دولوپرها
React‌ برای دولوپرهاWeb Standards School
 
The Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web appsThe Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web appsJohn Anderson
 
Future of Web Development
Future of Web DevelopmentFuture of Web Development
Future of Web DevelopmentZeno Rocha
 
Bootiful Development with Spring Boot and Angular - Spring I/O 2017
Bootiful Development with Spring Boot and Angular - Spring I/O 2017Bootiful Development with Spring Boot and Angular - Spring I/O 2017
Bootiful Development with Spring Boot and Angular - Spring I/O 2017Matt Raible
 
Frontend Finesse with Angular & Rails 4
Frontend Finesse with Angular & Rails 4Frontend Finesse with Angular & Rails 4
Frontend Finesse with Angular & Rails 4undecisive
 

Was ist angesagt? (20)

Engines
EnginesEngines
Engines
 
Up & running with ECMAScript6
Up & running with ECMAScript6Up & running with ECMAScript6
Up & running with ECMAScript6
 
I motion
I motionI motion
I motion
 
Ansible -new kid in configuration management world
Ansible -new kid in configuration management worldAnsible -new kid in configuration management world
Ansible -new kid in configuration management world
 
MVC-RS par Grégoire Lhotelier
MVC-RS par Grégoire LhotelierMVC-RS par Grégoire Lhotelier
MVC-RS par Grégoire Lhotelier
 
javascript for backend developers
javascript for backend developersjavascript for backend developers
javascript for backend developers
 
AngularJS performance & production tips
AngularJS performance & production tipsAngularJS performance & production tips
AngularJS performance & production tips
 
A little respect for MVC part 1 par Gegoire Lhotellier
A little respect for MVC part 1 par Gegoire LhotellierA little respect for MVC part 1 par Gegoire Lhotellier
A little respect for MVC part 1 par Gegoire Lhotellier
 
What's New in JHipsterLand - Devoxx Poland 2017
What's New in JHipsterLand - Devoxx Poland 2017What's New in JHipsterLand - Devoxx Poland 2017
What's New in JHipsterLand - Devoxx Poland 2017
 
Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017
 
Intro to UI-Router/TypeScript
Intro to UI-Router/TypeScriptIntro to UI-Router/TypeScript
Intro to UI-Router/TypeScript
 
Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love Ruby
 
Performance monitoring measurement angualrjs single page apps with phantomas
Performance monitoring measurement angualrjs single page apps with phantomasPerformance monitoring measurement angualrjs single page apps with phantomas
Performance monitoring measurement angualrjs single page apps with phantomas
 
React for Developers
React for DevelopersReact for Developers
React for Developers
 
React‌ برای دولوپرها
React‌ برای دولوپرهاReact‌ برای دولوپرها
React‌ برای دولوپرها
 
The Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web appsThe Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web apps
 
Future of Web Development
Future of Web DevelopmentFuture of Web Development
Future of Web Development
 
Bootiful Development with Spring Boot and Angular - Spring I/O 2017
Bootiful Development with Spring Boot and Angular - Spring I/O 2017Bootiful Development with Spring Boot and Angular - Spring I/O 2017
Bootiful Development with Spring Boot and Angular - Spring I/O 2017
 
Frontend Finesse with Angular & Rails 4
Frontend Finesse with Angular & Rails 4Frontend Finesse with Angular & Rails 4
Frontend Finesse with Angular & Rails 4
 
Sinatra
SinatraSinatra
Sinatra
 

Andere mochten auch

We Were All N00bs: Learning the Social Web by Using the Social Web
We Were All N00bs: Learning the Social Web by Using the Social WebWe Were All N00bs: Learning the Social Web by Using the Social Web
We Were All N00bs: Learning the Social Web by Using the Social WebNathan Flinchum
 
Downloading Books from BARD for Your Digital Player
Downloading Books from BARD for Your Digital PlayerDownloading Books from BARD for Your Digital Player
Downloading Books from BARD for Your Digital PlayerNathan Flinchum
 
PHP Deployment With Capistrano
PHP Deployment With CapistranoPHP Deployment With Capistrano
PHP Deployment With Capistranojserpieters
 
Get Hip Libraries And Gangsta Lit
Get Hip   Libraries And Gangsta LitGet Hip   Libraries And Gangsta Lit
Get Hip Libraries And Gangsta LitNathan Flinchum
 
Staff Training the Wiki Wacky Way!
Staff Training the Wiki Wacky Way!Staff Training the Wiki Wacky Way!
Staff Training the Wiki Wacky Way!Nathan Flinchum
 
Pillars.io wake upstartup
Pillars.io wake upstartupPillars.io wake upstartup
Pillars.io wake upstartupBrian Link
 
20150516 modern web_conf_tw
20150516 modern web_conf_tw20150516 modern web_conf_tw
20150516 modern web_conf_twTse-Ching Ho
 
Ruby on bioinformatics
Ruby on bioinformaticsRuby on bioinformatics
Ruby on bioinformaticsTse-Ching Ho
 
Building Great Software Engineering Teams
Building Great Software Engineering TeamsBuilding Great Software Engineering Teams
Building Great Software Engineering TeamsBrian Link
 
Ponencia PROFECO CENHIES
Ponencia PROFECO CENHIESPonencia PROFECO CENHIES
Ponencia PROFECO CENHIESEmmanuel Ameth
 
Gótika 2012 19_berry
Gótika 2012 19_berryGótika 2012 19_berry
Gótika 2012 19_berryeorsianna
 
Tema 2. Conocimiento
Tema 2. ConocimientoTema 2. Conocimiento
Tema 2. ConocimientoCarlos-9
 
Excursió a can joan
Excursió a can joanExcursió a can joan
Excursió a can joanmagefra
 
La prehistoria
La prehistoriaLa prehistoria
La prehistorianoeliask
 
Peras 091015103737-phpapp01
Peras 091015103737-phpapp01Peras 091015103737-phpapp01
Peras 091015103737-phpapp0104141998
 
Preliminary Task Storyboard
Preliminary Task StoryboardPreliminary Task Storyboard
Preliminary Task StoryboardHannahCostello
 
Estadisticas de los pueblos
Estadisticas de los pueblosEstadisticas de los pueblos
Estadisticas de los pueblosrubenm18
 

Andere mochten auch (20)

D40 16p
D40 16pD40 16p
D40 16p
 
We Were All N00bs: Learning the Social Web by Using the Social Web
We Were All N00bs: Learning the Social Web by Using the Social WebWe Were All N00bs: Learning the Social Web by Using the Social Web
We Were All N00bs: Learning the Social Web by Using the Social Web
 
Downloading Books from BARD for Your Digital Player
Downloading Books from BARD for Your Digital PlayerDownloading Books from BARD for Your Digital Player
Downloading Books from BARD for Your Digital Player
 
Puruchuco
PuruchucoPuruchuco
Puruchuco
 
PHP Deployment With Capistrano
PHP Deployment With CapistranoPHP Deployment With Capistrano
PHP Deployment With Capistrano
 
Get Hip Libraries And Gangsta Lit
Get Hip   Libraries And Gangsta LitGet Hip   Libraries And Gangsta Lit
Get Hip Libraries And Gangsta Lit
 
ruby e-commerce
ruby e-commerceruby e-commerce
ruby e-commerce
 
Staff Training the Wiki Wacky Way!
Staff Training the Wiki Wacky Way!Staff Training the Wiki Wacky Way!
Staff Training the Wiki Wacky Way!
 
Pillars.io wake upstartup
Pillars.io wake upstartupPillars.io wake upstartup
Pillars.io wake upstartup
 
20150516 modern web_conf_tw
20150516 modern web_conf_tw20150516 modern web_conf_tw
20150516 modern web_conf_tw
 
Ruby on bioinformatics
Ruby on bioinformaticsRuby on bioinformatics
Ruby on bioinformatics
 
Building Great Software Engineering Teams
Building Great Software Engineering TeamsBuilding Great Software Engineering Teams
Building Great Software Engineering Teams
 
Ponencia PROFECO CENHIES
Ponencia PROFECO CENHIESPonencia PROFECO CENHIES
Ponencia PROFECO CENHIES
 
Gótika 2012 19_berry
Gótika 2012 19_berryGótika 2012 19_berry
Gótika 2012 19_berry
 
Tema 2. Conocimiento
Tema 2. ConocimientoTema 2. Conocimiento
Tema 2. Conocimiento
 
Excursió a can joan
Excursió a can joanExcursió a can joan
Excursió a can joan
 
La prehistoria
La prehistoriaLa prehistoria
La prehistoria
 
Peras 091015103737-phpapp01
Peras 091015103737-phpapp01Peras 091015103737-phpapp01
Peras 091015103737-phpapp01
 
Preliminary Task Storyboard
Preliminary Task StoryboardPreliminary Task Storyboard
Preliminary Task Storyboard
 
Estadisticas de los pueblos
Estadisticas de los pueblosEstadisticas de los pueblos
Estadisticas de los pueblos
 

Ähnlich wie Rails-3-app-auto-generator-20100817

Integrating Browserify with Sprockets
Integrating Browserify with SprocketsIntegrating Browserify with Sprockets
Integrating Browserify with SprocketsSpike Brehm
 
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com RubyConsegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com RubyFabio Akita
 
Monkeybars in the Manor
Monkeybars in the ManorMonkeybars in the Manor
Monkeybars in the Manormartinbtt
 
Jaoo Michael Neale 09
Jaoo Michael Neale 09Jaoo Michael Neale 09
Jaoo Michael Neale 09Michael Neale
 
Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular applicationmirrec
 
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com RubyFisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com RubyFabio Akita
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developergicappa
 
Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!cloudbring
 
JRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the CloudJRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the CloudHiro Asari
 
Zepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-FrameworksZepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-FrameworksThomas Fuchs
 
Angular JS in 2017
Angular JS in 2017Angular JS in 2017
Angular JS in 2017Ayush Sharma
 
20141210 rakuten techtalk
20141210 rakuten techtalk20141210 rakuten techtalk
20141210 rakuten techtalkHiroshi SHIBATA
 
JRuby on Rails Deployment: What They Didn't Tell You
JRuby on Rails Deployment: What They Didn't Tell YouJRuby on Rails Deployment: What They Didn't Tell You
JRuby on Rails Deployment: What They Didn't Tell Youelliando dias
 
Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Clinton Dreisbach
 
Flu3nt highlights
Flu3nt highlightsFlu3nt highlights
Flu3nt highlightsdswork
 
introduction-infra-as-a-code using terraform
introduction-infra-as-a-code using terraformintroduction-infra-as-a-code using terraform
introduction-infra-as-a-code using terraformniyof97
 
ME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS FundamentalsME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS FundamentalsAviran Cohen
 
Damage Control
Damage ControlDamage Control
Damage Controlsintaxi
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Racksickill
 

Ähnlich wie Rails-3-app-auto-generator-20100817 (20)

Integrating Browserify with Sprockets
Integrating Browserify with SprocketsIntegrating Browserify with Sprockets
Integrating Browserify with Sprockets
 
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com RubyConsegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
 
Monkeybars in the Manor
Monkeybars in the ManorMonkeybars in the Manor
Monkeybars in the Manor
 
Jaoo Michael Neale 09
Jaoo Michael Neale 09Jaoo Michael Neale 09
Jaoo Michael Neale 09
 
Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular application
 
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com RubyFisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
 
Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!
 
JRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the CloudJRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the Cloud
 
Zepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-FrameworksZepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-Frameworks
 
Angular JS in 2017
Angular JS in 2017Angular JS in 2017
Angular JS in 2017
 
20141210 rakuten techtalk
20141210 rakuten techtalk20141210 rakuten techtalk
20141210 rakuten techtalk
 
JRuby on Rails Deployment: What They Didn't Tell You
JRuby on Rails Deployment: What They Didn't Tell YouJRuby on Rails Deployment: What They Didn't Tell You
JRuby on Rails Deployment: What They Didn't Tell You
 
Derailing rails
Derailing railsDerailing rails
Derailing rails
 
Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3
 
Flu3nt highlights
Flu3nt highlightsFlu3nt highlights
Flu3nt highlights
 
introduction-infra-as-a-code using terraform
introduction-infra-as-a-code using terraformintroduction-infra-as-a-code using terraform
introduction-infra-as-a-code using terraform
 
ME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS FundamentalsME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS Fundamentals
 
Damage Control
Damage ControlDamage Control
Damage Control
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
 

Mehr von Tse-Ching Ho

Ajax nested form and ajax upload in rails
Ajax nested form and ajax upload in railsAjax nested form and ajax upload in rails
Ajax nested form and ajax upload in railsTse-Ching Ho
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introductionTse-Ching Ho
 
devise tutorial - 2011 rubyconf taiwan
devise tutorial - 2011 rubyconf taiwandevise tutorial - 2011 rubyconf taiwan
devise tutorial - 2011 rubyconf taiwanTse-Ching Ho
 
model.search: customize your own search logic
model.search: customize your own search logicmodel.search: customize your own search logic
model.search: customize your own search logicTse-Ching Ho
 
The Power of Rails 2.3 Engines & Templates
The Power of Rails 2.3 Engines & TemplatesThe Power of Rails 2.3 Engines & Templates
The Power of Rails 2.3 Engines & TemplatesTse-Ching Ho
 

Mehr von Tse-Ching Ho (6)

Webconf2013
Webconf2013Webconf2013
Webconf2013
 
Ajax nested form and ajax upload in rails
Ajax nested form and ajax upload in railsAjax nested form and ajax upload in rails
Ajax nested form and ajax upload in rails
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introduction
 
devise tutorial - 2011 rubyconf taiwan
devise tutorial - 2011 rubyconf taiwandevise tutorial - 2011 rubyconf taiwan
devise tutorial - 2011 rubyconf taiwan
 
model.search: customize your own search logic
model.search: customize your own search logicmodel.search: customize your own search logic
model.search: customize your own search logic
 
The Power of Rails 2.3 Engines & Templates
The Power of Rails 2.3 Engines & TemplatesThe Power of Rails 2.3 Engines & Templates
The Power of Rails 2.3 Engines & Templates
 

Kürzlich hochgeladen

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Kürzlich hochgeladen (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Rails-3-app-auto-generator-20100817

  • 1. Rails 3 app auto-generator Tse-Ching Ho 2010/08/17 Ruby-Tuesday | ruby.tw
  • 2. It’s bored to always write the same codes.
  • 3. Who needs auto generator?
  • 4. NO, Rails Newbies!! Before you do it, You must understand what you are doing. You should play on local branch (git/mercurial). You should know each pieces of codes (Don’t generate trash). You need consistency between projects. You want be a time saver (Stop copy, paste and verify). You type codes as slow as me :(
  • 6. Modulate your codes Maintainability is a critical thing for long life projects. Reusability is valuable for programmers. Modules are everywhere in rails 3. Use it!
  • 7. Gemify your modules Be a ruby gem producer http://railscasts.com/episodes/218-making-generators-in-rails-3 jeweler --rspec --gemcutter my_awesome_gem bundle gem my_awesome_gem create my_awesome_gem/Gemfile create my_awesome_gem/Rakefile create my_awesome_gem/.gitignore create my_awesome_gem/my_awesome_gem.gemspec create my_awesome_gem/lib/my_awesome_gem.rb create my_awesome_gem/lib/my_awesome_gem/version.rb rake build rake install rake push
  • 8. Update to Rails 3 Be familiar with APIs of thor and rails 3 generator gsub_file 'public/stylesheets/blueprint/screen.css', /src/grid.png/, 'grid.png' inject_into_file 'config/application.rb', "n config.middleware.use Rack::Tidyn", :before => " end nendn" Keep updated by force/skip overwrite option rails generate responders:install -f
  • 11. Bundler Gemfile.lock should always keep updated in generators. gem 'simple_form' run 'bundle install' run 'bundle update' generate 'simple_form:install', '-s' Use gems, don’t use git branch. You should commit Gemfile.lock if you need consistency between development and production environment.
  • 12. JQuery get 'http://github.com/rails/jquery-ujs/raw/master/src/rails.js', 'public/ javascripts/rails.js' inject_into_file 'config/application.rb', " config.action_view.javascript_expansions[:defaults] = %w(jquery jquery-ui rails) n", :after => "# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)n", :verbose => false jqueryui.com only keeps the latest one zip file! http://jqueryui.com/download/jquery-ui-1.8.4.custom.zip
  • 13. Customized templates Rails.root/lib/templates/erb/scaffold/index.html.erb config.generators.scaffold_controller = :responders_controller config.generators do |g| g.orm :active_record g.template_engine :erb g.integration_tool :rspec g.test_framework :rspec g.scaffold :stylesheets => false end
  • 14. Migration files migration_template 'create_roles.rb', 'db/migrate/create_roles.rb' # Implement the required interface for Rails::Generators::Migration. def self.next_migration_number(dirname) #:nodoc: @next_migration_number = if @next_migration_number (@next_migration_number.to_i + 1).to_s elsif ActiveRecord::Base.timestamped_migrations Time.now.utc.strftime("%Y%m%d%H%M%S") else "%.3d" % (current_migration_number(dirname) + 1) end end def migration_template(source, destination=nil, config={}) super rescue Rails::Generators::Error => e puts e end
  • 15. What else? File.exist? File path source_root destination_root Rails.root Customized configuration files (config/xxx.rb)
  • 16. Make every practices as generator!
  • 17. Q&A
  • 18. About me Tse-Ching Ho (http://github.com/tsechingho) Use Rails 2 since 2008 Senior R&D programmer in techbang.tw (T ) now