Skip to content

Commit

Permalink
Generate resource user. Added datamapper database.yml.
Browse files Browse the repository at this point in the history
  • Loading branch information
harmon committed Oct 11, 2008
1 parent 30f0aec commit dbb7d31
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 6 deletions.
57 changes: 57 additions & 0 deletions app/controllers/users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class Users < Application
# provides :xml, :yaml, :js

def index
@users = User.all
display @users
end

def show
@user = User.get(params[:id])
raise NotFound unless @user
display @user
end

def new
only_provides :html
@user = User.new
render
end

def edit
only_provides :html
@user = User.get(params[:id])
raise NotFound unless @user
render
end

def create
@user = User.new(params[:user])
if @user.save
redirect url(:user, @user)
else
render :new
end
end

def update
@user = User.get(params[:id])
raise NotFound unless @user
if @user.update_attributes(params[:user]) || !@user.dirty?
redirect url(:user, @user)
else
raise BadRequest
end
end

def destroy
@user = User.get(params[:id])
raise NotFound unless @user
if @user.destroy
redirect url(:user)
else
raise BadRequest
end
end

end # Users
5 changes: 5 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Merb
module UsersHelper

end
end # Merb
5 changes: 5 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class User
include DataMapper::Resource


end
12 changes: 12 additions & 0 deletions app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<h1>Users controller, edit action</h1>

<p>Edit this file in <tt>app/views/users/edit.html.erb</tt></p>

<%= form_for(@user, :action => url(:user, @user)) do %>
<p>
<%= submit "Update" %>
</p>
<% end =%>

<%= link_to 'Show', url(:user, @user) %> |
<%= link_to 'Back', url(:users) %>
17 changes: 17 additions & 0 deletions app/views/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<h1>Users controller, index action</h1>

<p>Edit this file in <tt>app/views/users/index.html.erb</tt></p>

<table>
<tr>
</tr>

<% for user in @users %>
<tr>
<td><%= link_to 'Show', url(:user, user) %></td>
<td><%= link_to 'Edit', url(:edit_user, user) %></td>
</tr>
<% end %>
</table>

<%= link_to 'New', url(:new_user) %>
11 changes: 11 additions & 0 deletions app/views/users/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h1>Users controller, new action</h1>

<p>Edit this file in <tt>app/views/users/new.html.erb</tt></p>

<%= form_for(@user, :action => url(:users) ) do %>
<p>
<%= submit "Create" %>
</p>
<% end =%>

<%= link_to 'Back', url(:users) %>
7 changes: 7 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1>Users controller, show action</h1>

<p>Edit this file in <tt>app/views/users/show.html.erb</tt></p>


<%= link_to 'Edit', url(:edit_user, @user) %> |
<%= link_to 'Back', url(:users) %>
14 changes: 14 additions & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
:development: &defaults
:adapter: mysql
:database: pool_tracker_dev
:username: pool_tracker
:password: pool_tracker
:host: localhost

:test:
<<: *defaults
:database: sample_test

:production:
<<: *defaults
:database: sample_production
14 changes: 8 additions & 6 deletions config/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@
# These are a few, but not all, of the standard merb-more dependencies:
#
# dependency "merb-action-args" # Provides support for querystring arguments to be passed in to controller actions
# dependency "merb-assets" # Provides link_to, asset_path, auto_link, image_tag methods (and lots more)
# dependency "merb-helpers" # Provides the form, date/time, and other helpers
# dependency "merb-cache" # Provides your application with caching functions
# dependency "merb-haml" # Adds rake tasks and the haml generators to your merb app
# dependency "merb-jquery" # Provides a #jquery method to insert jQuery code in to a content block
dependency "merb-assets" # Provides link_to, asset_path, auto_link, image_tag methods (and lots more)
dependency "merb-helpers" # Provides the form, date/time, and other helpers
dependency "merb-cache" # Provides your application with caching functions
dependency "merb-haml" # Adds rake tasks and the haml generators to your merb app
dependency "merb-jquery" # Provides a #jquery method to insert jQuery code in to a content block
# dependency "merb-mailer" # Integrates mail support via Merb Mailer
dependency "dm-core"

# These are a few, but not all, of the merb-plugin dependencies:
#
Expand All @@ -72,6 +73,7 @@
# For example, the magic_admin gem uses the app's model classes. This requires that the models be
# loaded already. So, we can put the magic_admin dependency here:
# dependency "magic_admin"
DataMapper.setup(:default, 'mysql://localhost/dm_core_test')
end

#
Expand All @@ -83,7 +85,7 @@
# if you need a database.

# Uncomment for DataMapper ORM
# use_orm :datamapper
use_orm :datamapper

# Uncomment for ActiveRecord ORM
# use_orm :activerecord
Expand Down
2 changes: 2 additions & 0 deletions config/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
# RESTful routes
# resources :posts

match('/').to(:controller => 'home', :action => 'index')

# This is the default route for /:controller/:action/:id
# This is fine for most cases. If you're heavily using resource-based
# routes, you may want to comment/remove this line to prevent
Expand Down
7 changes: 7 additions & 0 deletions spec/controllers/users_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')

describe Users, "index action" do
before(:each) do
dispatch_to(Users, :index)
end
end
5 changes: 5 additions & 0 deletions spec/helpers/users_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')

describe Merb::UsersHelper do

end
7 changes: 7 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require File.join( File.dirname(__FILE__), '..', "spec_helper" )

describe User do

it "should have specs"

end

0 comments on commit dbb7d31

Please sign in to comment.