Skip to content

Commit

Permalink
Improvements to WidgetsController and its views ...
Browse files Browse the repository at this point in the history
  - More idiomatic use of labels
  - Be sure to hide_action for non-public-facing actions
  • Loading branch information
jasonrudolph committed Sep 21, 2008
1 parent 7f01a14 commit 98705e1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
3 changes: 2 additions & 1 deletion rails_samples/app/controllers/widgets_controller.rb
Expand Up @@ -5,11 +5,12 @@ class WidgetsController < ApplicationController

# codecite require_login
before_filter :require_login, :except => "login"
# codecite require_login

def require_login
redirect_to :action => "login" unless session[:username]
end
hide_action :require_login
# codecite require_login

# codecite dump
def dump
Expand Down
8 changes: 4 additions & 4 deletions rails_samples/app/views/widgets/index.html.erb
Expand Up @@ -10,9 +10,9 @@
<%#codecite list %>
<% for widget in @widgets %>
<tr>
<td><%= widget.name %></td>
<td><%= widget.weight %></td>
<td><%= widget.color %></td>
<td><%= widget.name %></td>
<td><%= widget.weight %></td>
<td><%= widget.color %></td>
<td><%= link_to 'Show', widget %></td>
<td><%= link_to 'Edit', edit_widget_path(widget) %></td>
<td><%= link_to 'Destroy', widget, :confirm => 'Are you sure?', :method => :delete %></td>
Expand All @@ -31,7 +31,7 @@
<%#codecite search %>
<form>
<p>
<label for="search">Search</label>:<br />
<%= label_tag 'search' %><br/>
<%= text_field_tag :search, params[:search] %>
</p>
<p>
Expand Down
11 changes: 6 additions & 5 deletions rails_samples/app/views/widgets/new.html.erb
@@ -1,20 +1,21 @@
<h1>New widget</h1>

<%= error_messages_for :widget %>
<% form_for(@widget) do |f| %>
<%= f.error_messages %>

<p>
<label for="widget[name]">Name</label>:<br />
<%= f.label :name %>
<%= f.text_field :name %>
</p>
<p>
<label for="widget[weight]">Weight</label>:<br />
<%= f.label :weight %>
<%= f.text_field :weight %>
</p>
<p>
<label for="widget[color]">Color</label>:<br />
<%= f.label :color %>
<%= f.text_field :color %>
</p>

<p>
<%= f.submit "Create" %>
</p>
Expand Down
15 changes: 9 additions & 6 deletions rails_samples/app/views/widgets/show.html.erb
@@ -1,11 +1,14 @@
<h1>Widget <%= @widget.name %></h1>

<dl>
<dt>Weight</dt>
<dd><%= @widget.weight %></dd>
<dt>Color</dt>
<dd><%= @widget.color %></dd>
</dl>
<p>
<b>Weight:</b>
<%= @widget.weight %>
</p>

<p>
<b>Color:</b>
<%= @widget.color %>
</p>

<%= link_to 'Edit', edit_widget_path(@widget) %> |
<%= link_to 'Back', widgets_path %>

0 comments on commit 98705e1

Please sign in to comment.