In the previous section, we demonstrated how to build a list of items, and this time we built a simple shopping cart based on the previous content.
1. First we want to create a table that holds customer shopping information:
Database scripts:
drop table if exists line_items;
CREATE TABLE Line_items (
ID int not NULL auto_increment,
product_id int not null,
quantity int NOT null DEFAU Lt 0,
unit_price decimal (10,2) NOT NULL,
constraint fk_items_product foreign key (product_id) references Pro
The last Test Modeul problem has not been resolved, but the following to continue, this time to test controller.
1. In the test\functional directory, rails has generated a corresponding test file for our controller, and note that Application_controller does not generate test files. Let's take control of the login Logincontroller as an example, open the LOGIN_CONTROLLER_TEST.RB, which reads as follows:
Require File.dirname (__file__) + '/... /test_h
The most frequently run query on a database is to return a conforming result set based on a specified condition, and the query may be to return all the names ' Dave's order, or all the titles on a blog with rails, in many other frameworks and programming languages, you need to create SQL to execute queries, and Active record takes advantage of the dynamic capabilities that the Ruby language contains.
For e
Because in some cases you want to use a nonexistent column, or you want to create a new virtual modelYou can create a new tableless.rb under concerns under models, with the following code:Module tablelessdef self.included (Base)Base.extend (Classmethods)Base.send (: Include,instancemethods)EndModule Instancemethodsdef save (Validate = True)Validate? Valid? : TrueEndEndModule Classmethodsdef column (name, Sql_type = nil, default = nil, NULL = TRUE)Columns sql_type.to_s, NULL)Enddef columns@column
After several days, the Ror environment was finally ready. In order to prevent future forgetting and minimize detours, we made a special record
========================================================== =====
Installation Process
1. Install rubyinstaller-1.9.2
2. install and execute gem install rails
3. Download dev kit and decompress it to the ruby installation directory.
4. Install Netbeans 6.9.1
5. Enabl
Http://www.songlin51.com/archives/667.html
Ubuntu 12.04 redmine2.1 installation record
When you install gem install rails, you cannot connect to rails.
Solution: Search for railson http://rubygems.org/gems/railsto download rails. gem for installation.
An error is reported when installing gem install mysql2.Building native extensions. This cocould take a while
Let's take a look at some tips for debugging this time.
First, and most importantly, writing test code, writing unit tests and functional tests in rails is simple, using them to reduce the rate of bugs, or to avoid bugs in your previous code.
The test code tells you what works and what doesn't, and the test code helps you isolate the problematic code, because sometimes the bug doesn't show up quickly.
If the problem occurs in a model, we can use th
A Brief Introduction to Ruby on Rails's support for PostgreSQL array types, railspostgresql
I am very happy to announce that Rails 4.0 now supports PostgreSQL array types. you can easily create fields of the array type through: array => true in migration. you can also add other options (length, default, and so on) when creating an array field)
create_table :table_with_arrays do |t| t.integer :int_array, :ar
Modify viewsModify the index view (app/views/posts/index.html.erb) and add the edit link as follows:That is, add the following logic: Among them, Edit_post_path, is the previous "[Ruby on Rails] and I learned route map" referred to the edit action prefix added a shortcut after the _path suffix, can accept parameters, here accept the post instance object.Then edit the view and copy the new view as an edit v
Using form to create data, this section will cover the content: Create form, redirect user, render views and flash messages.1. Views PreliminaryEdit App/views/posts/index.html.erb This view file as follows:New_post is the new action's prefix, referring to [Ruby on Rails] and I learned the route map, but after it added the _path suffix.Then edit the App/views/posts/new.html.erb view file as follows:2. Bindin
Deploying Network application Services is a hassle, installing programs, upgrading database schemas, switching versions, and restarting services. The more steps, the more human involvement, the more prone to problems.
Capistrano is Ruby on Rails to provide the deployment solution, the original name Switchtower, a lot of names, the results and people heavy, replaced now this, it is estimated to be in order
In the previous Ruby on Rails development from scratch (Windows) (iii)-Implementation of the jump between pages, we created two pages for the jump migration, this time we write a single form of maintenance of the TIM Delete Check the example.
1. This time we recreate a project depot, and follow the steps in the previous article to create a depot project.
2. Create a database.
You can use the
In the practice of agile development, the test drive is indispensable. This article looks at a test-driven development example in rails.
Before we wrote and conducted some unit tests and functional tests, our customers suddenly asked to add a feature: Each user of the system could query the product.
We first sketched some sketches to sort out our ideas and designs, and then we started writing code. We already have a general idea of what to do, but i
user model that contains first_name, last_name, nickname, where the nickname field is an array type. The following migration code creates the corresponding table:
Create_table:users do |t|
T.string:first_name
t.string:last_name
t.string:nicknames,: Array => true
end
And for this table, we have a simple model
Class User
We do not use the default value for the field, if we instance a user object, the code is like this.
John = User.create (: first_name => ' J
Up to now, should come to an ending, altogether has 29 essays, simply gather together an integer, then write the IDE environment. All the previous code was written by me with the editor scite in Ruby, and it was inconvenient, as rails developed, there are many Ides coming out, just to see the 6.0RC version of NetBeans offering a separate rails development environ
The essay briefly understands the use of rails ' test and test data, and this time to see how to add a test to a model for deletion and modification.
1. Or using the last written products_test.rb, modify the Test_turth method by the name Test_create and make the contents:
def test_create
assert_kind_of Product, @product
assert_equal 1, @product. ID
assert_equal "pragmatic Ver Sion control ", @product. Title
assert_equal" I to use version control ",
I mainly use two plug-ins: rinari and Yari.
Rinari supports fast jump to multiple files in the rails project. In addition, it provides the grep tool, which I found useful. The shortcut keys are easy to remember.
Yari provides an Emacs interface for the RI tool that comes with Ruby, which is compatible with the latest Ruby and easy to operate. You only need to u
Active support is a set of libraries provided with rails, active support extends some of the classes in Ruby, and this time we'll look at some of the most common features.
1. Extension of the number type
The Fixnum class adds two methods: even and odd?
The scaling method is also added:
Puts 20.bytes #=> 20
Puts 20.kilobytes #=> 20480
Puts 20.megabytes #=> 20971520
Puts 20.gigabytes #=> 21474836480
P
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.