Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding nested_form gem

  • Loading branch information...
commit c1d97a60e817359f80efa53b4b40eb2b3e35be6f 1 parent 338b0b6
@paulcook authored
View
1  Gemfile
@@ -22,6 +22,7 @@ group :assets do
end
gem 'jquery-rails'
+gem "nested_form"
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
View
6 Gemfile.lock
@@ -43,8 +43,8 @@ GEM
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
- jquery-rails (2.0.0)
- railties (>= 3.2.0.beta, < 5.0)
+ jquery-rails (2.0.1)
+ railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.6.5)
mail (2.4.1)
@@ -53,6 +53,7 @@ GEM
treetop (~> 1.4.8)
mime-types (1.17.2)
multi_json (1.1.0)
+ nested_form (0.2.0)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.1)
@@ -106,6 +107,7 @@ DEPENDENCIES
coffee-rails (~> 3.2.1)
jquery-rails
json
+ nested_form
rails (= 3.2.0)
sass-rails (~> 3.2.3)
sqlite3
View
3  app/controllers/trips_controller.rb
@@ -1,9 +1,12 @@
class TripsController < ApplicationController
def index
+
end
def new
+ @trip = Trip.new
+ @trip.legs.build
end
def create
View
3  app/models/trip.rb
@@ -1,2 +1,5 @@
class Trip < ActiveRecord::Base
+ has_many :legs
+
+ accepts_nested_attributes_for :legs
end
View
2  app/views/index/index.html.erb
@@ -1,3 +1,3 @@
<h1>Index#index</h1>
<p>Find me in app/views/index/index.html.erb</p>
-<%= link_to "Add Step", new_trip_step_path(@trip) %>
+<%= link_to "Add Step", new_trip_path(@trip) %>
View
36 app/views/trips/_form.html.erb
@@ -0,0 +1,36 @@
+<%= form_for(@trip) do |f| %>
+ <% if @trip.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@leg.errors.count, "error") %> prohibited this leg from being saved:</h2>
+
+ <ul>
+ <% @leg.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name, :size=>30 %>
+ </div>
+ <%= f.fields_for :legs do |l| %>
+ <div class="field">
+ <%= l.label :location %><br />
+ <%= l.text_field :location %>
+ </div>
+ <div class="field">
+ <%= l.label :depart_arrive_type %><br />
+ <%= l.select :depart_arrive_type, ["Departure", "Arrival"] %>
+
+ </div>
+ <div class="field">
+ <%= l.label :depart_arrive %><br />
+ <%= l.datetime_select :depart_arrive %>
+ </div>
+ <% end %>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
View
2  app/views/trips/new.html.erb
@@ -1,2 +1,2 @@
<h1>Trip#new</h1>
-<p>Find me in app/views/trip/new.html.erb</p>
+<%= render "form" %>
View
10 config/routes.rb
@@ -1,15 +1,7 @@
Tripd::Application.routes.draw do
- get "trip/index"
-
- get "trip/new"
-
- get "trip/create"
-
- get "trip/edit"
-
- get "trip/update"
+ resources :trips
resources :legs
# The priority is based upon order of creation:
Please sign in to comment.
Something went wrong with that request. Please try again.