Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update Rails examples based on latest scaffold generator

  • Loading branch information...
commit 40ae5757cba9a4ce9e8faf889fec435370daf929 1 parent 8ff2602
@obrie obrie authored
View
6 examples/rails-rest/migration.rb
@@ -1,11 +1,7 @@
class CreateUsers < ActiveRecord::Migration
- def self.up
+ def change
create_table :users do |t|
t.string :name, :state, :access_state
end
end
-
- def self.down
- drop_table :users
- end
end
View
34 examples/rails-rest/view__form.html.erb
@@ -0,0 +1,34 @@
+<%= form_for(@user) do |f| %>
+ <% if @user.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
+
+ <ul>
+ <% @user.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+
+ <% unless @user.new_record? %>
+ <div class="field">
+ <%= f.label :state %><br />
+ <%= f.collection_select :state_event, @user.state_transitions, :event, :human_to_name, :include_blank => @user.human_state_name %>
+ </div>
+
+ <div class="field">
+ <%= f.label :access_state %><br />
+ <%= f.collection_select :access_state_event, @user.access_state_transitions, :event, :human_event, :include_blank => "don't change" %>
+ </div>
+ <% end %>
+
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
View
23 examples/rails-rest/view_edit.html.erb
@@ -1,25 +1,6 @@
-<h1>Editing User</h1>
+<h1>Editing user</h1>
-<% form_for(@user) do |f| %>
- <%= f.error_messages %>
-
- <p>
- <%= f.label :name %><br />
- <%= f.text_field :name %>
- </p>
-
- <p>
- <%= f.label :state %><br />
- <%= f.collection_select :state_event, @user.state_transitions, :event, :human_to_name, :include_blank => @user.human_state_name %>
- </p>
-
- <p>
- <%= f.label :access_state %><br />
- <%= f.collection_select :access_state_event, @user.access_state_transitions, :event, :human_event, :include_blank => "don't change" %>
- </p>
-
- <p><%= f.submit 'Update' %></p>
-<% end %>
+<%= render 'form' %>
<%= link_to 'Show', @user %> |
<%= link_to 'Back', users_path %>
View
10 examples/rails-rest/view_index.html.erb
@@ -1,17 +1,19 @@
-<h1>Listing Users</h1>
+<h1>Listing users</h1>
<table>
<tr>
<th>Name</th>
<th>State</th>
<th>Access State</th>
+ <th></th>
+ <th></th>
</tr>
<% @users.each do |user| %>
<tr>
- <td><%=h user.name %></td>
- <td><%=h user.human_state_name %></td>
- <td><%=h user.human_access_state_name %></td>
+ <td><%= user.name %></td>
+ <td><%= user.human_state_name %></td>
+ <td><%= user.human_access_state_name %></td>
<td><%= link_to 'Show', user %></td>
<td><%= link_to 'Edit', edit_user_path(user) %></td>
</tr>
View
13 examples/rails-rest/view_new.html.erb
@@ -1,14 +1,5 @@
-<h1>New User</h1>
+<h1>New user</h1>
-<% form_for @user do |f| %>
- <%= f.error_messages %>
-
- <p>
- <%= f.label :name %><br />
- <%= f.text_field :name %>
- </p>
-
- <p><%= f.submit 'Create' %></p>
-<% end %>
+<%= render 'form' %>
<%= link_to 'Back', users_path %>
View
8 examples/rails-rest/view_show.html.erb
@@ -1,16 +1,18 @@
+<p id="notice"><%= notice %></p>
+
<p>
<b>Name:</b>
- <%=h @user.name %>
+ <%= @user.name %>
</p>
<p>
<b>State:</b>
- <%=h @user.human_state_name %>
+ <%= @user.human_state_name %>
</p>
<p>
<b>Access State:</b>
- <%=h @user.human_access_state_name %>
+ <%= @user.human_access_state_name %>
</p>
<%= link_to 'Edit', edit_user_path(@user) %> |
Please sign in to comment.
Something went wrong with that request. Please try again.