`
sillycat
  • 浏览: 2551830 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Rails Study(I)Getting Started with Rails

阅读更多
Rails Study(I)Getting Started with Rails

1. MVC Architecture
1.1. Models
One table in my database will correspond to one model in my application.
The bulk of my application's bussiness logic will be concentrated in the models.

1.2. Views
Views are often HTML files with embedded Ruby code that perform tasks related solely to the presentation of the data.

1.3. Controllers
Controllers provide the "glue" between models and views.

2. The Components of Rails
Action Pack
  Action Controller
  Action Dispatch
  Action View
Action Mailer
Action Model
Action Record
Action Resource
Active Support
Railties

2.1 Action Pack
2.1.1 Action Controller
Action Controller processes incoming requests to a Rails application, extracts parameters, and dispatches them to the intended
action.

Services provided by Action Controller include session management, template rendering, and redirect management.

2.1.2 Action view
Action view can create both HTML and XML output. Action View manages rendering templates, including nested and partial
templates, and includes built-in AJAX support.

2.1.3 Action Dispatch
2.1.4 Action Mailer
A framework for building e-mail services.

2.1.5 Action Model
Action Model -----> Business Logic -----> ORM

2.1.6 Action Record
CRUD functionality

2.1.7 Action Resource
2.1.8 Action Support

2.2 REST

3. Creating a New Rails Project
Creating a Blog Application
>rails new railsexample

or I can create a rails project in eclipse.

type >rails -h in eclipse command console for more information.

File              Purpose
Gemfile         This file allows you to specify what gem dependencies are needed for your Rails application
Readme         
Rakefile         This file contains batch jobs that can be run from the terminal
config.ru        Rack configuration for Rack based servers used to start the application.

Folder         Purpose
app             Contains the controllers, models, and views for your application. You'll focus on this folder for the remainder of this
                  guide.
config          Configure your application's runtime rules, routes, database, and more.
db               Shows your current database schema
doc            
lib                Extended modules for my application
log
public           This is where you put your images, javasript, stylesheets(CSS), and other static files.
script           Contains the rails script that starts your app and can contain other scripts you use to deploy or run applications
test
tmp
vendor         A place for all third-party code. In a typical Rails application, this includes Ruby Gems, the Rails source code (if you install
                  it into your project) and plugins containing additional prepackaged functionality.

3.1 Installing the Required Gems
>bundle install

3.2 Configuring a Database
config/database.yml

3.2.1 Configuring an SQLite3 Database
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

3.2.2 Configuring a MySQL Database
development:  
  adapter: mysql2  
  encoding: utf8  
  database: example_development  
  pool: 5  
  username: root  
  password:  
  socket: /tmp/mysql.sock

3.3 Creating the Database
>rake db:create

error message:
rake aborted!
uninitialized constant Rake::DSL
d:/tool/Ruby192/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
d:/tool/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/tasklib.rb:8:in `<class:TaskLib>'

Solutions:
Change the Rakefile

require File.expand_path('../config/application', __FILE__)
require 'rake/dsl_definition'

module ::Railsexample
  class Application
    include Rake::DSL
  end
end

module ::RakeFileUtils
  extend Rake::FileUtilsExt
end

Railsexample::Application.load_tasks

>bundle update
>rake db:create

error message:
uninitialized constant Mysql2

solution:
>gem install mysql2
Fetching: mysql2-0.3.6.gem (100%)

error message:
ERROR:  Error installing mysql2:
        The 'mysql2' native gem requires installed build tools.

Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'

solution:
Download the file DevKit-tdm-32-4.5.2-20110712-1620-sfx.exe in 7zip format from that URL
Create a directory devkit and unzip the file there with 7zip software.
Copy the directory devkit to d:/tool/devkit
>cd d:/tool/devkit
>ruby dk.rb init
This step will list the installation of ruby and generate a file named config.yml
>ruby dk.rb install

After all the steps, do install mysql2 again.
>gem install mysql2
No, but the problem is still there.

>gem install mysql2 -v 0.2.6 --platform x86-mingw32

change Gemfile and add one line
gem 'mysql2', '0.2.6'

>rake db:create

error message:
The program can't start because LIBMYSQL.dll is missing from your
computer. Try reinstalling the program to fix this problem.

solution:
Copy file D:\ProgramFiles\MySQL\MySQL Server 5.5\lib\libmysql.dll to directory D:\tool\Ruby192\bin

try again. >rake db:create

error message:
193: %1 is not a valid Win32 application.   - d:/tool/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x
86-mingw32/lib/mysql2/1.9/mysql2.so

try other ways
>gem install mysql2 -v 0.2.6 -- --with-mysql-dir="D:\ProgramFiles\MySQL\MySQL Server 5.5"

try other ways
>gem install mysql2 -- --with-mysql-lib="D:\ProgramFiles\MySQL\MySQL Server 5.5\lib" --with-mysql-include="D:\ProgramFiles\MySQL\MySQL Server 5.5\include" --with-mysql-dir="D:\ProgramFiles\MySQL\MySQL Server 5.5"

try other ways
Gemfile
gem 'mysql', '2.8.1'

adapter mysql

>bundle install
>rake db:create
>gem list -d mysql
Same problem.

Finally I download the file from http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/libmySQL.dll
and put this file to ruby_home/bin.
>rake db:create
It works.

references:
http://guides.rubyonrails.org/
https://github.com/oneclick/rubyinstaller/wiki/Development-Kit
http://www.iteye.com/topic/1001758

分享到:
评论

相关推荐

    Agile Web Development with Rails 4

    If you’re an experienced developer, this book will give you the comprehensive, insider information you need., Rails has evolved over the years, and this book has evolved along with it. We still ...

    Agile+Web+Development+with+Rails中文版.pdf

    《Agile Web Development with Rails》是一本经典的Rails开发指南,中文版的出版使得更多的中国开发者能够深入理解并应用敏捷开发方法与Ruby on Rails框架。这本书是Rails开发者的必备参考资料,它详细介绍了如何...

    rails-getting-started

    Radcircle 开发入门学习在线资源 - Ruby 和 Ruby on Rails - Ruby 和一些 Ruby on Rails - Ruby on Rails(必须有账号,但有 14 天免费试用) - 不错的 Rails 和 Ruby 备忘单 - 免费的 rails 截屏视频,非常有帮助,...

    Agile Web Development with Rails

    书中的"Pragmatic.Bookshelf.Agile.Web.Development.with.Rails.2nd.Edition.Dec.2006.eBook-BBL"可能是该书籍的电子版文件,它包含了全书的章节和内容。读者可以通过这个电子版深入学习Rails开发的各种技巧和最佳...

    Agile Web Development with Rails (PDF)

    《敏捷Web开发与Rails》是一本深度探讨如何利用Ruby on Rails框架进行敏捷Web开发的指导书籍,由Dave Thomas、David Heinemeier Hansson等多位在Rails社区有着深厚贡献的作者共同编写。本书不仅覆盖了Rails的基本...

    Ajax on Rails

    For those new to Rails, this book provides a quick introduction, the big picture, a walk through the installation process, and some tips on getting started. If you've already started working with ...

    rails2-sample

    Getting Started(入门) 在这一部分,作者将引导读者如何安装和配置Ruby on Rails环境,包括Ruby语言本身、Rails框架以及相关的工具和库。这里还会涉及如何创建第一个Rails项目,以及如何运行服务器以查看项目。...

    Agile Web Development with Rails 3nd Edition Beta.pdf

    ### 敏捷Web开发与Rails 3:关键知识点解析 #### 一、Rails版本与兼容性 本书《敏捷Web开发与Rails》第三版是基于Rails 2编写的。截至本书印刷时,当前可用的Rails Gem版本为2.1。书中所包含的所有代码均已在该...

    Agile Web Development With Ruby On Rails第一及第二版

    《Agile Web Development With Ruby On Rails》是两本广受欢迎的书籍,主要涵盖了使用Ruby on Rails框架进行敏捷Web开发的知识。这本书的第1版和第2版分别详细讲解了如何运用敏捷开发方法来构建高效、可扩展且易于...

    RailsSpace

    第五章“Getting started with testing”引导读者进入测试驱动开发的世界。本章首先介绍了测试的重要性,并逐步指导读者如何为Rails应用编写单元测试。通过实际案例,读者可以学习到如何使用RSpec和Capybara等测试...

    Agile Web Development with Rails 4th edition(敏捷Web开发与Rails:程序指南 第四版)

    《敏捷Web开发与Rails:程序指南 第四版》是一本深度探讨使用Ruby on Rails框架进行敏捷Web应用开发的专业书籍。本书旨在帮助开发者充分利用Rails 4的特性,提高开发效率,实现快速迭代和高质量的代码编写。 Rails是...

    [Michael Hartl] Ruby on Rails Tutorial

    Learn Web Development with Rails Clear EPUB version in English, Second Edition “The author is clearly an expert at the Ruby language and the Rails framework, but more than that, he is a working ...

Global site tag (gtag.js) - Google Analytics