`
jiajie0531
  • 浏览: 29537 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Active Record Basics 3 Creating Active Record Models

阅读更多

version: rails4

3 创建Active Record 模型

 

创建Active Record models是非常简单的。你所需要做的就是实现 ActiveRecord::Base的子类, 你可以参考下面:

classProduct < ActiveRecord::Base

end

这会创建一个Product model,在数据库中映射一个products数据表。你将能够映射数据表每一行的列对应于模型实例的特性。正如同products数据表是用下文的SQL语句来创建的:

CREATETABLEproducts (

   id int(11) NOTNULLauto_increment,

   namevarchar(255),

   PRIMARYKEY  (id)

);

基于上文的数据表模式,你将能够编写如下的代码:

p = Product.new

p.name = "Some Book"

puts p.name # "Some Book"

 

 

 

original text: http://guides.rubyonrails.org/active_record_basics.html#creating-active-record-models

0
0
分享到:
评论

相关推荐

    Active Directory Cookbook, 3rd Edition.pdf

    Covers the basics of searching Active Directory: creating, modifying, and deleting objects, using LDAP controls, and importing and exporting data using LDAP Data Interchange Format (LDIF) and comma-...

    Pro ActiveRecord Databases

    And almost all of those books actually do a great job of introducing you to the basics of Active Record; they go a long way toward getting you started with the library. However, because they ...

    Qt 3D basics

    Qt 3D是Qt框架中用于3D图形和渲染的应用程序编程接口(API),它的主要目标是提供一个跨平台的解决方案,用于在软件中实现3D内容的展示和交互。该技术适用于游戏开发、模拟系统、数据可视化以及任何需要3D图形显示的...

    Part 2: Understanding the basics of Backbone Models

    在本文中,我们将深入理解Backbone Models的基本概念,这是Backbone框架的核心组件之一。 **Backbone Models** Backbone Models是数据的容器,它们负责存储应用程序中的数据和业务逻辑。模型通常与服务器上的数据...

    Linux Basics for Hackers (AZW3)

    Linux Basics for Hackers: Getting Started with Networking, Scripting, and Security in Kali (AZW3)

    MPLS Basics MPLS Basics

    MPLS BasicsMPLS Basics

    Learn Autodesk Inventor 2018 Basics 3D Modeling, 2D Graphics, and 无水印pdf

    Learn Autodesk Inventor 2018 Basics 3D Modeling, 2D Graphics, and Assembly Design 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者...

    HTML Basics

    Welcome to HTML Basics. This workshop leads you through the basics of Hyper Text Markup Language (HTML). HTML is the building block for web pages. You will learn to use HTML to author an HTML page to ...

    FFmpeg Basics.zip

    3. **FFmpeg 命令行操作** 使用FFmpeg通常通过命令行进行,例如,你可以使用`ffmpeg -i input.mp4 output.mp3`命令将MP4视频的音频提取为MP3。学习如何构造FFmpeg命令,可以实现复杂的音视频处理任务,如裁剪、合并...

    Mastering Probabilistic Graphical Models using Python(PACKT,2015)

    This book starts with the basics of probability theory and graph theory, then goes on to discuss various models and inference algorithms. All the different types of models are discussed along with ...

    iOS 11 Programming Fundamentals with Swift Swift, Xcode, and Cocoa Basics azw3

    iOS 11 Programming Fundamentals with Swift Swift, Xcode, and Cocoa Basics 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    LabWindows CVI BASICS I & II

    本系列教程“LabWindows CVI BASICS I & II”旨在帮助初学者和有一定经验的工程师掌握这款强大的工具的基础知识。 在“CVI BASICS I Course”中,学习者将深入理解LabWindows CVI的基础概念和核心功能。这部分教程...

    OpenLayers 3.x Cookbook - Second Edition 随书代码

    You will get to grips with the basics of creating a map with common functionality and quickly advance to more complicated solutions that address modern challenges. You will explore into maps, raster ...

    Joomla! 3 Beginne's Guide

    Chapter 4: Web Building Basics: Creating a Site in an Hour Chapter 5: Small Sites, Big Sites: Organizing your Content Effectively Chapter 6: Creating Killer Content: Adding and Editing Articles ...

    Blender 3D Basics_Beginner's Guide,Second Edition-Packt Publishing(2014)

    - **版本信息**:本书主要介绍了Blender 2.7版本的使用方法,虽然当前版本已经更新至更高版本(如2.9x或3.x系列),但2.7版本的基础概念和操作仍然适用于后续版本。 #### 知识点二:书籍作者与出版信息 - **作者...

    The Basics of Cloud Computing

    The Basics of Cloud Computing

    SAP CRM 100 Basics

    3. **客户服务和支持**:提供工具和技术来改善客户体验,增强客户满意度和忠诚度。 4. **商务智能**:集成数据分析工具,帮助企业从大量数据中提取有价值的信息,辅助决策制定。 #### 三、技术规格和兼容性 文档中...

    Cloud Computing Basics

    Cloud Computing Basics springer 2014

    Blockchain Basics A Non-Technical Introduction in 25 Steps epub

    Blockchain Basics A Non-Technical Introduction in 25 Steps 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

Global site tag (gtag.js) - Google Analytics