Skip to content

Commit

Permalink
view changes so html works
Browse files Browse the repository at this point in the history
  • Loading branch information
darkhelmet committed Aug 21, 2009
1 parent 77f4cfa commit 9da9d47
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 10 deletions.
20 changes: 10 additions & 10 deletions app/controllers/widgets_controller.rb
Expand Up @@ -2,48 +2,48 @@ class WidgetsController < ApplicationController
def index
@widgets = widget_class.all
respond_to do |format|
format.html
format.html { render(:template => "widgets/index") }
format.js { render(:json => @widgets) }
end
end

def show
@widget = widget_class.find(params[:id])
respond_to do |format|
format.html
format.html { render(:template => "widgets/show") }
format.js { render(:json => @widget.to_json(:methods => [:valid])) }
end
end

def new
@widget = widget_class.new
respond_to do |format|
format.html
format.html { render(:template => "widgets/new") }
end
end

def edit
@widget = widget_class.find(params[:id])
respond_to do |format|
format.html
format.html { render(:template => "widgets/edit") }
format.js { render(:json => @widget.to_json(:methods => [:valid])) }
end
end

def create
@widget = widget_class.new(params[:widget])
@widget = widget_class.new(params[widget_symbol])
@widget.save
respond_to do |format|
format.html
format.html { redirect_to(@widget) }
format.js { render(:json => @widget.to_json(:methods => [:valid])) }
end
end

def update
@widget = widget_class.find(params[:id])
@widget.update_attributes(params[:widget])
@widget.update_attributes(params[widget_symbol])
respond_to do |format|
format.html
format.html { redirect_to(@widget) }
format.js { render(:json => @widget.to_json(:methods => [:valid])) }
end
end
Expand All @@ -52,7 +52,7 @@ def destroy
@widget = widget_class.find(params[:id])
@widget.destroy
respond_to do |format|
format.html
format.html { redirect_to(fancy_widgets_path) }
format.js { head(:ok) }
end
end
Expand All @@ -64,6 +64,6 @@ def widget_class
end

def widget_symbol
params[:controller].singular.intern
params[:controller].singularize.intern
end
end
20 changes: 20 additions & 0 deletions app/views/widgets/edit.html.erb
@@ -0,0 +1,20 @@
<h1>Editing <%= params[:controller].humanize %></h1>

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

<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :description %><br />
<%= f.text_area :description %>
</p>
<p>
<%= f.submit 'Update' %>
</p>
<% end %>
<%= link_to 'Show', @widget %> |
<%= link_to 'Back', eval("#{params[:controller].singularize}_path") %>
22 changes: 22 additions & 0 deletions app/views/widgets/index.html.erb
@@ -0,0 +1,22 @@
<h1>Listing <%= params[:controller].humanize %></h1>

<table>
<tr>
<th>Name</th>
<th>Description</th>
</tr>

<% @widgets.each do |widget| %>
<tr>
<td><%=h widget.name %></td>
<td><%=h widget.description %></td>
<td><%= link_to 'Show', widget %></td>
<td><%= link_to 'Edit', eval("edit_#{params[:controller].singularize}_path(widget)") %></td>
<td><%= link_to 'Destroy', widget, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New widget', eval("new_#{params[:controller].singularize}_path") %>
19 changes: 19 additions & 0 deletions app/views/widgets/new.html.erb
@@ -0,0 +1,19 @@
<h1>New <%= params[:controller].humanize %></h1>

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

<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :description %><br />
<%= f.text_area :description %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>
<%= link_to 'Back', eval("#{params[:controller]}_path") %>
12 changes: 12 additions & 0 deletions app/views/widgets/show.html.erb
@@ -0,0 +1,12 @@
<p>
<b>Name:</b>
<%=h @widget.name %>
</p>

<p>
<b>Description:</b>
<%=h @widget.description %>
</p>


<%= link_to 'Edit', eval("edit_#{params[:controller].singularize}_path(@widget)") %>
4 changes: 4 additions & 0 deletions config/routes.rb
@@ -1,4 +1,8 @@
ActionController::Routing::Routes.draw do |map|
map.resources :widgets

map.resources :foos

map.resources :fancy_widgets
map.resources :weird_widgets

Expand Down

0 comments on commit 9da9d47

Please sign in to comment.