Learning Rails 3

Learning Rails 3

Simon St. Laurent, Edd Dumbill, Eric J. Gruber

Language: English

Pages: 414

ISBN: 144930933X

Format: PDF / Kindle (mobi) / ePub


If you’re a web developer or designer ready to learn Rails, this unique book is the ideal way to start.

Rather than throw you into the middle of the framework’s Model-View-Controller architecture, Learning Rails 3 works from the outside in. You’ll begin with the foundations of the Web you already know, and learn how to create something visible with Rails’ view layer. Then you’ll tackle the more difficult inner layers: the database models and controller code.

All you need to get started is HTML experience. Each chapter includes exercises and review questions to test your understanding as you go.

  • Present content by building an application with a basic view and a simple controller
  • Build forms and process their results, progressing from simple to more complex
  • Connect forms to models by setting up a database, and create code that maps to database structures
  • Use Rails scaffolding to build applications from a view-centric perspective
  • Add common web application elements such as sessions, cookies, and authentication
  • Build applications that combine data from multiple tables
  • Send and receive email messages from your applications

"Learning Rails 3 feels like a brisk pair programming session with professionals who know how to use Ruby on Rails to get things done, and get them done well."
-Alan Harris, author of Sinatra: Up and Running

Lightweight Django

HTML5 and CSS3 Responsive Web Design Cookbook

Web Performance Daybook Volume 2

Getting Started with Drupal Commerce

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Person.find(params[:id]) end # POST /people # POST /people.json def create @person = Person.new(params[:person]) respond_to do |format| if @person.save format.html { redirect_to @person, notice: 'Person was successfully created.' } format.json { render json: @person, status: :created, location: @person } else Examining a RESTful Controller | 65 format.html { render action: "new" } format.json { render json: @person.errors, status: :unprocessable_entity } end end end # PUT /people/1 # PUT

Connecting Students to Awards | 147 Figure 9-6. A students list complete with count of awards

Awards

<% for award in @student.awards %>

<% end %>

Name Year Student
<%= award.name %> <%= award.year %> <%= award.student.name %>

In the view, the @student variable contains the current student. Running a for loop over the collection returned by @student.awards, which contains only the awards for

clearly reflects its relationship to students, implemented in ch09/students02. 148 | Chapter 9: Developing Model Relationships Figure 9-7. A student record with awards listed The models will stay the same, and the views will stay almost the same. The main things that will change are the routing and the controller logic. Chapter 13 will explain routing in much greater depth, but for now it’s worth exploring the ways that routing can reflect the relationships of your data models. If the work

to produce the code in ch09/students03. And also as usual, while Rails provides you with a foundation, you’re still going to need to add a lot to that foundation. Remember, don’t name a table “classes,” or you will have all kinds of strange Rails disasters because of name conflicts. “Courses” is a safer option. Creating Tables Building a many-to-many relationship requires creating tables—not just a single table, but a many-to-many relationship that will require adding two tables beyond the

establish the target for the form’s results. If the first argument is a single object, it will create a URL pointing to that object. If the first argument is an array containing more than one object, it assumes that the first object contains the second, and generates a URL reflecting a nested resource relationship. 8. A join table needs a column to store id values for each of the two models it connects. By Rails conventions, these columns are named model_id. A column linking to students, for

Download sample

Download