Skip to content

Commit

Permalink
adding nested_form gem
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcook committed Mar 2, 2012
1 parent 338b0b6 commit c1d97a6
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 13 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -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'
Expand Down
6 changes: 4 additions & 2 deletions Gemfile.lock
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions 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
Expand Down
3 changes: 3 additions & 0 deletions app/models/trip.rb
@@ -1,2 +1,5 @@
class Trip < ActiveRecord::Base
has_many :legs

accepts_nested_attributes_for :legs
end
2 changes: 1 addition & 1 deletion 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) %>
36 changes: 36 additions & 0 deletions 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 %>
2 changes: 1 addition & 1 deletion 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" %>
10 changes: 1 addition & 9 deletions 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:
Expand Down

0 comments on commit c1d97a6

Please sign in to comment.