|
|
| About site: Programming/Languages/Ruby/Software/Rails/FAQs, Help, and Tutorials - Rolling with Ruby on Rails, Part 2 |
Return to Computers also Computers |
| About site: http://www.onlamp.com/pub/a/onlamp/2005/03/03/rails.html |
Title: Programming/Languages/Ruby/Software/Rails/FAQs, Help, and Tutorials - Rolling with Ruby on Rails, Part 2 Curt Hibbs shows off RoR by finishing sample application in 47 lines of code. Descriptions, instructions, screenshots. [ONLamp.com] (March 3, 2005) |
|
|
|
|
Chart2D A library written in Java for adding two dimensional charts to Java programs.
| Ada_Utilities Several useful Ada utilities and bindings includes AdaGOOP (the Ada Generator of Object-Oriented Parsers), bindings to use parallel, serial ports under Windows.
| University_of_Cape_Town Department of Computer Science. Research laboratories: Collaborative Visual Computing, Data Network Architectures, and Databases.
| On_Target_Technologies,_Inc_ Provides consulting services for Hyperion Essbase, DB2 OLAP and Microsoft Analysis Services.
| Press_Digital_Australia Supplier of Microsoft Windows powered mobile computing solutions includes PDAs, Smartphones, GPS and office equipment.
| Meta_Workshop Multi-functional toolbox, which allows an image to be swiftly and easily turn into a repeatable tile. Tiles can be used as textures for 3D objects. Texture Workshop lets you modify the obtained tile b
|
|
| Alexa statistic for http://www.onlamp.com/pub/a/onlamp/2005/03/03/rails.html |
Please visit: http://www.onlamp.com/pub/a/onlamp/2005/03/03/rails.html
|
| Related sites for http://www.onlamp.com/pub/a/onlamp/2005/03/03/rails.html |
| Multimedia_Applications_of_IEEE_1394 Written by Lawrence A. Rowe at U.C. Berkeley. | | RFC_2285 Benchmarking Terminology for LAN Switching Devices. R. Mandeville. February 1998. | | RFC_0912 Authentication Service. M. St. Johns. September 1984. | | CodeWorker A parsing tool and a source code generator works on generative programming. It offers facilities for building a DSL, for generating code, for source-to-source translation or program transformation, fo | | Web-cache_com Link collection organized by subcategories including products and services, projects, mailing lists, benchmarking, filtering, and privacy. | | Net_Resources_Training_ Edinburgh-based internet training company. Courses include HTML, Dreamweaver and Flash. | | Gamer_Heaven Internet and Lan Gaming Centre offering PC and Xbox gaming machines and Internet access. Located in Brighton, East Sussex, UK. | | THINK_Subscription Provides services and technology to manage subscriptions, memberships, and time-based products on the web. | | PALO Open Source OLAP Server for analysis, reporting, budgeting, forecasting, and planning. | | Feedthebot_com The Google webmaster guidelines explained in everyday terms by Patrick Sexton. | | phpNewsManager A news manager for web sites. Supports multi-level user access, weekly poll and customizable color settings. | | RFC_0918 Post Office Protocol. J.K. Reynolds. October 1984. | | RFC_2549 IP over Avian Carriers with Quality of Service. D. Waitzman. April 1999. | | Happy_Software Offers applications for administering housing programs including the 50058, Family Self-Sufficiency, and Residential Rehabilitation programs. | | On_Ruby__Ruby_Hacker_Interview___Kevin_Tew Kevin Tew, Cardinal creator and project director explains project motives, direction, progress. (September 12, 2006) | | Grove21_Websites Offers web design, custom web graphics, search engine submission and hosting. | | DCC_Web_Designs Offers web design and development services. | | Sokoloff,_Nichole Visual, design, and interior design. | | iGrabNews Shareware binary newsgroup browser and download manager for Mac OS X. | | WebLion Project aimed to distribute a Plone CMS for use by various departments at Penn State and eventually other various Higher Education Institutions. |
|
This is websites2007.org cache of m/ as retrieved on 2008.10.06 websites2007.org's cache is the snapshot that we took of the page as we crawled the web. The page may have changed since that time.
|
Rolling with Ruby on Rails, Part 2 | O'Reilly Media
var _hbEC=0,_hbE=new Array;function _hbEvent(a,b){b=_hbE[_hbEC++]=new Object();b._N=a;b._C=0;return b;} var hbx=_hbEvent("pv");hbx.vpc="HBX0100u";hbx.gn="ehg-oreilly.hitbox.com"; //"BCB: onlamp.com,/a/onlamp/2005/03/03/rails.html, DM550308O2RV"; hbx.acct="DM550308O2RV;DM520404M4ZR"; //ACCOUNT NUMBER(S) hbx.pn="Rolling+with+Ruby+on+Rails,+Part+2"; //PAGE NAME(S) hbx.mlc="/a/onlamp/2005/03/03/;/onlamp.com/a/onlamp/2005/03/03/"; //MULTI-LEVEL CONTENT CATEGORY hbx.pndef="title"; //DEFAULT PAGE NAME hbx.ctdef="full"; //DEFAULT CONTENT CATEGORY hbx.lt="auto"; //LINK TRACKING hbx.dlf="n"; //DOWNLOAD FILTER hbx.dft="n"; //DOWNLOAD FILE NAMING hbx.elf="n"; //EXIT LINK FILTER //SEGMENTS AND FUNNELS hbx.seg=""; //VISITOR SEGMENTATION hbx.fnl=""; //FUNNELS //CAMPAIGNS hbx.cmp=""; //CAMPAIGN ID hbx.cmpn="CMP"; //CAMPAIGN ID IN QUERY hbx.hra=""; //RESPONSE ATTRIBUTE hbx.hqsr=""; //RESPONSE ATTRIBUTE IN REFERRAL QUERY hbx.hqsp="ATT"; //RESPONSE ATTRIBUTE IN QUERY hbx.hlt=""; //LEAD TRACKING hbx.hla=""; //LEAD ATTRIBUTE hbx.gp=""; //CAMPAIGN GOAL hbx.gpn=""; //CAMPAIGN GOAL IN QUERY hbx.hcn=""; //CONVERSION ATTRIBUTE hbx.hcv=""; //CONVERSION VALUE hbx.cp="null"; //LEGACY CAMPAIGN hbx.cpd=""; //CAMPAIGN DOMAIN //CUSTOM VARIABLES hbx.ci="";//CUSTOMER ID hbx.hc1="";//CUSTOM 1 hbx.hc2="";//CUSTOM 2 hbx.hc3="";//CUSTOM 3 hbx.hc4="";//CUSTOM 4 hbx.pec="";//ERROR CODES
addLoadEvent(function(e) {
jaTooltip.initTooltips("tt", {
urlFunc: function(elem) {
return "/feeds/widgets/most_commented_blogs/" + elem.id + ".html"
}
});
});
Sign In/My Account | View Cart
#search-box {
background-color:#F6F6F6;
border-bottom:1px solid #CCCCCC;
padding-top:11px;
text-align:center;
}
#search-form {
margin:0pt auto;
text-align:left;
width:400px;
}
#search-title {
color:#888888;
display:block;
float:left;
font-size:17px;
padding:5px 5px 4px 0pt;
}
#search-input {
background:transparent url(http://www.oreilly.com/images/oreilly/search_bar_mid.gif) repeat-y scroll left top;
display:block;
float:left;
padding:0pt 5px 0pt 0pt;
width:260px;
}
#search-input-top {
background:transparent url(http://www.oreilly.com/images/oreilly/search_bar_top.gif) no-repeat scroll left top;
display:block;
width:260px;
}
#search-input-bot {
background:transparent url(http://www.oreilly.com/images/oreilly/search_bar_bot.gif) no-repeat scroll left bottom;
display:block;
width:260px;
}
#search-field {
float:left;
}
#search-field input {
background:transparent none repeat scroll 0%;
border:0pt none;
color:#990000;
font-family:Verdana,Arial,Helvetica,sans-serif;
font-size:16px;
margin:0pt;
padding:3px 0pt 4px 10px;
width:215px;
}
#search-field input:focus {
outline-color:invert;
outline-style:none;
outline-width:0pt;
}
#search-button {
float:right;
}
#search-button input {
font-size:0pt;
height:18px;
line-height:0pt;
margin:4px 4px 2px 0pt;
padding:0pt;
width:28px;
}
#search-tips {
display:block;
float:left;
font-size:10px;
padding:6px 0pt 0pt;
}
#search label {
text-transform:uppercase;
}
#search legend {
display:none;
}
#search label {
left:-9999px;
position:absolute;
}
fieldset {
border:0pt none;
margin:0pt;
padding:0pt;
}
.clear {
display:block;
line-height:0pt;
}
#wrapper {
margin:1em 0pt 2em 19em;
overflow:hidden;
}
#features {
float:left;
margin:0pt;
padding:0pt 2em 0pt 0pt;
width:41em;
a{text-decoration:none;}
#search-box{
padding-top: 11px;
padding-bottom: 0pt;
background-color: #f6f6f6;
border-bottom-width: 1px;
border-top-style: solid;
border-top-width: 1px;
border-top-color: #cccccc;
border-bottom-style: solid;
border-bottom-color: #cccccc;
text-align: center;
}
O'Reilly Home
Community
Store
Safari Books Online
Conferences
School of Technology
About
#search-box {
background-color:#F6F6F6;
border-bottom:1px solid #CCCCCC;
padding-top:11px;
text-align:center;
}
#search-form {
margin:0pt auto;
text-align:left;
width:400px;
}
#search-title {
color:#888888;
display:block;
float:left;
font-size:17px;
padding:5px 5px 4px 0pt;
}
#search-input {
background:transparent url(http://www.oreilly.com/images/oreilly/search_bar_mid.gif) repeat-y scroll left top;
display:block;
float:left;
padding:0pt 5px 0pt 0pt;
width:260px;
}
#search-input-top {
background:transparent url(http://www.oreilly.com/images/oreilly/search_bar_top.gif) no-repeat scroll left top;
display:block;
width:260px;
}
#search-input-bot {
background:transparent url(http://www.oreilly.com/images/oreilly/search_bar_bot.gif) no-repeat scroll left bottom;
display:block;
width:260px;
}
#search-field {
float:left;
}
#search-field input {
background:transparent none repeat scroll 0%;
border:0pt none;
color:#990000;
font-family:Verdana,Arial,Helvetica,sans-serif;
font-size:16px;
margin:0pt;
padding:3px 0pt 4px 10px;
width:215px;
}
#search-field input:focus {
outline-color:invert;
outline-style:none;
outline-width:0pt;
}
#search-button {
float:right;
}
#search-button input {
font-size:0pt;
height:18px;
line-height:0pt;
margin:4px 4px 2px 0pt;
padding:0pt;
width:28px;
}
#search-tips {
display:block;
float:left;
font-size:10px;
padding:6px 0pt 0pt;
}
#search label {
text-transform:uppercase;
}
#search legend {
display:none;
}
#search label {
left:-9999px;
position:absolute;
}
fieldset {
border:0pt none;
margin:0pt;
padding:0pt;
}
.clear {
display:block;
line-height:0pt;
}
#wrapper {
margin:1em 0pt 2em 19em;
overflow:hidden;
}
#features {
float:left;
margin:0pt;
padding:0pt 2em 0pt 0pt;
width:41em;
#search-box{
padding-top: 11px;
padding-bottom: 0pt;
background-color: #f6f6f6;
border-bottom-width: 1px;
border-top-style: solid;
border-top-width: 1px;
border-top-color: #cccccc;
border-bottom-style: solid;
border-bottom-color: #cccccc;
text-align: center;
}
We've expanded our LAMP news coverage and improved our search! Search for all things LAMP across O'Reilly!
Search
Search Tips
var addthis_pub = 'odewahn';
Listen PrintDiscussSubscribe to ONLampSubscribe to Newsletters
Rolling with Ruby on Rails, Part 2
by Curt Hibbs
03/03/2005
Editor's note: Curt Hibbs and Bill Walton have updated this tutorial for Rails 1.2 in Rolling with
Ruby on Rails Revisited and Rolling with Ruby on Rails Revisited, Part Two. We recommend those tutorials for all new Rails development.
Also check out Bill Walton's monthly series, Cookin' With Ruby on Rails.
Welcome back!
In Rolling with
Ruby on Rails, I barely scratched the surface of what you can do with Ruby
on Rails. I didn't talk about data validation or database transactions, and I
did not mention callbacks, unit testing, or caching. There was hardly a mention
of the many helpers that Rails includes to make your life easier. I can't really
do justice to all of these topics in the space of this article, but I will go
into details on some of them and present a brief overview of the
rest, with links to more detailed information.
Related ReadingRuby on Rails: Up and Running: Rough Cuts VersionBy Bruce A. Tate, Curt Hibbs
Are you ready? Let's begin!
Updating Ruby on Rails
When I wrote Part 1,
the current version of Rails was 0.9.3. At the time of this writing, Rails is
up to version 0.10.0 and has some useful new features. I will use Rails 0.10.0
for this article. If you installed Rails after February 24, 2005, you already have
0.10.0 installed.
Figure 1 shows how to see what RubyGems you have installed (and their
version numbers). As with Part 1, I am working on a Windows system, so you
will need to translate if you use a different platform.
Figure 1. Listing installed RubyGems
Open a command window and run the command:
gem list --local
Tip: the command gem list --remote will show all the available
RubyGems on the remote gem server on rubyforge.org.
If you don't have Rails 0.10.0 (or later) installed, then you will need to
rerun the command:
gem install rails
MySQL security update
In Part 1, I recommended that you leave the MySQL root password blank
because (at the time of writing) Rails did not support MySQL's new password
protocol. Many of you were not happy with this state of affairs, and to make
matters worse, there is now a virus that exploits password vulnerabilities in
MySQL on Windows.
Happily, starting with version 0.9.4, Rails now supports the new password
protocol.
New scaffold feature
Rails has a new scaffold feature, which I won't explore here, but it's cool enough
that I want to make sure you know about it. This is best illustrated by an
example.
Part 1 showed how to create a recipe model and controller with the
commands:
ruby script\generate model Recipe
ruby script\generate controller Recipe
I then instantiated the scaffolding by inserting scaffold
:recipe into the RecipeController class. The resulting CRUD
controllers and view templates were created on the fly and are not visible for
inspection.
The technique described above still works, but you now have another option. Run the command:
ruby script\generate scaffold Recipe
This generates both the model and the controller, plus it creates scaffold
code and view templates for all CRUD operations. This allows you to see the
scaffold code and modify it to meet your needs. Be careful using this if you've
already created models, controllers, or view templates, as it will overwrite any
existing files as it creates the scaffold code.
Completing the Recipe Application
It's time to round out the recipe application a bit. After that I'll present
some other features of Rails that I'm sure you'll want to know about.
Remember that I created my cookbook application in the directory
c:\rails\cookbook; all paths used in this article assume this base
directory. If you chose a different location, please be sure to make the proper
adjustments to the application paths you see in this article.
You can also download my cookbook source code for this tutorial in
one single zip file. This works with Rails 0.13 and later, so if you're
still using an older version, I suggest that you follow the upgrade
instructions.
For those of you who are cheating (you know who you are) and plan to just download
my source code without going through Part 1, you will also need to create a
database named cookbook in MySQL and populate it using cookbook.sql.
Creating a new recipe with a category
Because the code still relies on the scaffolding to create new recipes,
there is no way to assign a category to a recipe. This wouldn't be so bad--except that the page created to list all recipes assumes that every recipe will
have a category, and it generates an error if this is not true. That means that in the way I left things in Part 1, if you add a new recipe, you'll receive
errors while trying to list them.
The fix is to take over the new action from the scaffolding just as I showed
already with the edit action. Edit
c:\rails\cookbook\app\controllers\recipe_controller.rb and add a
new method like in Figure 2.
Figure 2. The Recipe controller's new method
The code @recipe = Recipe.new creates a new, empty recipe
object and assigns it to the instance variable @recipe. Remember,
an instance of the Recipe class represents a row in the recipes
database table. When creating a new recipe object, the Recipe class can assign
default values for each field that the view template can use.
The Recipe model class doesn't currently set any such default values, but
the view template I'll show off momentarily will use whatever is in the
@recipe object to initialize the display form. Later, you could
add default values in the Recipe class that will show up when you create a new
recipe.
As with the edit action, this also retrieves a collection of all categories
so that it can display a drop-down list of categories from which the user can
choose. The @categories instance variable holds this list of
categories.
In the directory c:\rails\cookbook\app\views\recipe, create a file
named new.rhtml that contains the HTML template shown below. It's
mostly standard HTML, with some extra code to create the
<select> and <option> tags for the
drop-down list of categories:
<html>
<head>
<title>New Recipe</title>
</head>
<body>
<h1>New Recipe</h1>
<form action="/recipe/create" method="post">
<p>
<b>Title</b><br/>
<input id="recipe_title" name="recipe[title]" size="30" type="text" value=""/>
</p>
<p>
<b>Description</b><br/>
<input id="recipe_description" name="recipe[description]"
size="30" type="text" value=""/>
</p>
<p>
<b>Category:</b><br/>
<select name="recipe[category_id]">
<% @categories.each do |category| %>
<option value="<%= category.id %>">
<%= category.name %>
</option>
<% end %>
</select>
</p>
<p>
<b>Instructions</b><br/>
<textarea cols="40" id="recipe_instructions" name="recipe[instructions]"
rows="20" wrap="virtual">
</textarea>
</p>
<input type="submit" value="Create"/>
</form>
<a href="http://www.onlamp.com//recipe/list">Back</a>
</body>
</html>
This is not much different from the edit template from Part 1. I left out
the recipe's date because I'll set it to the current date when a user posts the
form back to the web app. This ensures that the recipe's date will always be
its creation date.
If you look at the form tag, you will see that this form will post to a
create action in the recipe controller. Edit
c:\rails\cookbook\app\controllers\recipe_controller.rb and add this
create method:
def create
@recipe = Recipe.new(@params['recipe'])
@recipe.date = Date.today
if @recipe.save
redirect_to :action => 'list'
else
render_action 'new'
end
end
This method first creates a new recipe object and initializes it from the
parameters posted by the form in new.rhtml. Then it sets the recipe's
date to today's date, and tells the recipe object to save itself to the
database. If the save is successful, it redirects to the list action that
displays all recipes. If the save fails, it redirects back to the new action so
the user can try again.
Give it a try. Start the web server by opening a command window, navigating
to c:\rails\cookbook, and running the command ruby
script\server. Then browse to http://127.0.0.1:3000/recipe/new
and add a new recipe like the one shown in Figure 3.
Figure 3. Adding a new recipe with a category
After you create the new recipe, you should see something like Figure 4.
Figure 4. List of all recipes
Pages: 1, 2, 3
Next Page
Port 25
Planning to Migrate to MySQL 6.0 on Windows? Read About its New Backup and Start Testing Now Todd OgasawaraCisco Buys PostPath! Dustin PuryearExchange vs. Open Source Dustin PuryearImportant PHP 5.3 Changes for those of you Running Microsoft Windows Todd OgasawaraFedora Authentication Server Breached: Do People Run Production Servers Using Fedora??? Todd OgasawaraHas the Microsoft-Novell SUSE Certificates Affected Linux Virtualization Support? Todd OgasawaraMySQL Drizzle Project Todd OgasawaraBlackbox for Windows! Dustin Puryear
More from Port 25
var akApiKey = 'RecEngine-49CCF850-02C7-B730-5489-DB7D929405CD';
var akTarget = 'http://www.onlamp.com/pub/a/onlamp/2005/03/03/rails.html';
var akDescription = 'Rolling with Ruby on Rails, Part 2';
var akThumbnailUrl = 'http://oreilly.com/images/oreilly/onlamp.png';
var akTargetType = 'article';
var akRegion = 'OnLampArticle';
var akIntent = 'VIEW';
var akScript = document.createElement('script');
var akKeywords = 'publishDate:20050303';
akScript.setAttribute('src','http://api.aggregateknowledge.com/2007/01/15/js/' + (new Date()).valueOf() % 3600000 + '.js');
document.getElementsByTagName('head')[0].appendChild(akScript);
.stats_most_commented { clear: right; } .stats_most_commented img { float: left; } .popup_area { width: 350px; border: 1px solid black; background-color: white; z-index: 999 !important; } .popup_header { background: url(/images/oreilly/popup_bkg.jpg) repeat-x top left; color:#fff; text-align: left; font-size:16px; font-family: Verdana, sans-serif; font-weight:bold; padding: 3px; } .popup_text { font-size:12px !important; font-family: Verdana, sans-serif !important; padding: 14px; } On the Blogs The technologies and issues being discussed across the O'Reilly Network.
Sponsored Resources
Inside Lightroom
|
|
| |
Curt | Hibbs | shows | off | RoR | by | finishing | sample | application | in | 47 | lines | of | code. | Descriptions, | instructions, | screenshots. | [ONLamp.com] | (March | 3, | 2005) |
|
http://www.onlamp.com/pub/a/onlamp/2005/03/03/rails.html
Rolling with Ruby on Rails, Part 2 2008 October
dvd rental
dvd
Curt Hibbs shows off RoR by finishing sample application in 47 lines of code. Descriptions, instructions, screenshots. [ONLamp.com] (March 3, 2005)
Rules
|
© 2008 Internet Explorer 5+ or Netscape 6+
|
|
Recommended Sites: 1.
Arts -
Business -
Computers -
Games -
Health -
Home -
Kids and Teens -
News -
Recreation -
Reference -
Regional -
Science -
Shopping -
Society -
Sports -
World
Miss Gallery
- Top Anime Hentai
- DVD rental by mail
- Bad Credit Mortgages - Loans - Cell Phones - Loans - Best Credit Cards
|