Agile web development with rails Reading Notes (2)

Source: Internet
Author: User
The debugging process was still smooth yesterday. However, because the integrated development environment was not used in the development process, the development process was slow as a whole. I will use the command line to create a database later, the server will be started again later, and the file will be edited later. A large number of windows are opened, which makes it very uncomfortable.

The editor scite included in the ROR installation package is good, but it is only an editor, not an integrated development environment. So today's main job is to find a better integrated development environment, A waste of time.

At the beginning, VIM was used. Although the configuration was successful, several required plug-ins were used. However, it was quite awkward to use and complicated to operate Mandarin, the most terrible thing is that you need to remember a lot of commands. Later, you chose the development tool radrails. It still feels good. Therefore, it is strongly recommended that you use this tool first. The effect is good, you can download some templates from the Internet. Readrails configuration and precautions: there are already a few good articles on the InternetArticleYou can Google it.

The rest of today is to complete the rest of Chapter 1CodeThe general content is as follows:

Modify module product. Rb

Class Product < Activerecord :: Base
# Determines whether the specified field is empty.
Validates_presence_of : Title ,: Description ,: Img_url
# Determines whether the price of a specified field is a number.
Validates_numericality_of : Price
# Determines whether the title of a book is unique.
Validates_uniqueness_of : Title
# Determine whether the img_url format is valid
Validates_format_of : Img_url ,: With =>   % R { ^ HTTP :. + \. (GIF | JPG | PNG) $} I ,
: Message =>   " Must be a URL for a GIF, JPG, or PNG image. "  
# The validate function is automatically called before the product instance.
Def validate
# Determine whether it is a positive number
Errors . Add ( : Price , " Shocould be positive " ) Unless Price . Nil ?   | Price > =   0.01
End
End

Among them, the ruby syntax can be viewed on the http://rubycn.ce-lab.net, I feel that the syntax is still well understood, that is, not used to, always need to view the manual.

Modify View list. rhtml

< H1 > Listing Products </ H1 >

< Table Cellpadding = "5" Cellspacing = "0" >
<%
Odd_or_even =   0
For Product in @ Products
Odd_or_even =   1   - Odd_or_even
%>
< Tr Valign = "TOP" Class = "Listline <% = odd_or_even %>" >
< TD >
< IMG Width = "60" Heithg = "70" SRC = "<% = Product. img_url %>" >
</ TD >
< TD Width = "60%" >
< Span Class = "Listtitle" >
<% = H (product. Title) %> </ BR >
<% = H (truncate (product. description, 80 )) %>
</ Span >
</ TD >
< TD Aligh = "Right" >
<% = Product. date_available.strftime ( " % Y-% m-% d " ) %> </ BR >
< Strong > <% = Sprintf ( " % 0.2f " , Product. Price) %> </ Strong >
</ TD >
< TD Class = "Listactions" >
<% = Link_to ' Show ',: Action => 'show',: Id => product %> <br/>
< % = Link_to ' Edit',: Action => 'edit',: Id => product %> <br/>
< % = Link_to ' Destroy ', {: Action => 'deststroy',: Id => product},: Confirm =>' Are you sure? ',: Method =>: Post %>
</ TD >
</ Tr >
< % End   %>
</ Table >

<% = Link_to ' Previous Page ', {: page => @ product_pages.current.previous} If @ product_pages.current.previous %>
< % = Link_to ' Next page ', {: page => @ product_pages.current.next} If @ product_pages.current.next %>

< BR />

<%=Link_to'New product',: Action => 'new' %>

Some of these statements are frequently used, such as the H function, truncate, sprintf, and date_available.strftime.

Add the following code to the modified Sample Table scaffold.css:

. Listtitle {
Color : #244 ;
Font-weight : Bold ;
Font-size : Larger ;
}

. Listactions {
Font-size : X-small ;
Text-align : Right ;
Padding-left : Lem ;
  }
 
. Listline0 {
Background : # E0f8f8 ;
}

. Listline1{
Background:# F8b0f8;
}

Come on step by step. Let's get started with a good development environment and speed up learning. But pay attention to the fact that with this tool, you may be reluctant to remember the ROR command, this is not enough. Remember it.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.