iain-pizza-generators 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/Manifest +113 -0
  2. data/README.rdoc +34 -12
  3. data/Rakefile +2 -2
  4. data/pizza-generators.gemspec +16 -13
  5. data/rails_generators/pizza_authentication/pizza_authentication_generator.rb +32 -24
  6. data/rails_generators/pizza_authentication/templates/authentication.rb +35 -9
  7. data/rails_generators/pizza_authentication/templates/factories.rb +24 -0
  8. data/rails_generators/pizza_authentication/templates/initializer.rb +5 -0
  9. data/rails_generators/pizza_authentication/templates/migration.rb +14 -4
  10. data/rails_generators/pizza_authentication/templates/session.rb +1 -0
  11. data/rails_generators/pizza_authentication/templates/sessions_controller.rb +17 -15
  12. data/rails_generators/pizza_authentication/templates/tests/rspec/sessions_controller.rb +104 -21
  13. data/rails_generators/pizza_authentication/templates/tests/rspec/user.rb +81 -29
  14. data/rails_generators/pizza_authentication/templates/tests/rspec/users_controller.rb +1 -1
  15. data/rails_generators/pizza_authentication/templates/tests/testunit/sessions_controller.rb +8 -4
  16. data/rails_generators/pizza_authentication/templates/tests/testunit/users_controller.rb +2 -2
  17. data/rails_generators/pizza_authentication/templates/user.rb +16 -1
  18. data/rails_generators/pizza_authentication/templates/users_controller.rb +32 -7
  19. data/rails_generators/pizza_authentication/templates/views/haml/edit.html.haml +21 -0
  20. data/rails_generators/pizza_authentication/templates/views/haml/login.html.haml +2 -2
  21. data/rails_generators/pizza_authentication/templates/views/haml/new.html.haml +19 -0
  22. data/rails_generators/pizza_authentication/templates/views/haml/show.html.haml +15 -0
  23. data/rails_generators/pizza_authentication/templates/views/haml/signup.html.haml +3 -2
  24. data/rails_generators/pizza_scaffold/pizza_scaffold_generator.rb +4 -5
  25. data/rails_generators/pizza_scaffold/templates/actions/create.rb +15 -3
  26. data/rails_generators/pizza_scaffold/templates/actions/destroy.rb +10 -3
  27. data/rails_generators/pizza_scaffold/templates/actions/edit.rb +4 -0
  28. data/rails_generators/pizza_scaffold/templates/actions/index.rb +9 -2
  29. data/rails_generators/pizza_scaffold/templates/actions/new.rb +10 -0
  30. data/rails_generators/pizza_scaffold/templates/actions/show.rb +10 -0
  31. data/rails_generators/pizza_scaffold/templates/actions/update.rb +15 -3
  32. data/rails_generators/pizza_scaffold/templates/controller.rb +1 -7
  33. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/create.rb +78 -10
  34. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/destroy.rb +28 -6
  35. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/edit.rb +12 -4
  36. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/index.rb +29 -4
  37. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/new.rb +29 -4
  38. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/show.rb +26 -4
  39. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/update.rb +72 -10
  40. data/rails_generators/pizza_scaffold/templates/tests/rspec/controller.rb +3 -3
  41. data/rails_generators/pizza_scaffold/templates/views/haml/_form.html.haml +4 -5
  42. data/rails_generators/pizza_scaffold/templates/views/haml/edit.html.haml +3 -5
  43. data/rails_generators/pizza_scaffold/templates/views/haml/index.html.haml +7 -6
  44. data/rails_generators/pizza_scaffold/templates/views/haml/new.html.haml +2 -4
  45. data/rails_generators/pizza_scaffold/templates/views/haml/show.html.haml +3 -5
  46. metadata +127 -104
@@ -1,24 +1,26 @@
1
- class <%= user_session_plural_class_name %>Controller < ResourceController::Singleton
1
+ class <%= user_session_plural_class_name %>Controller < ApplicationController
2
2
 
3
- actions :new, :create, :destroy
3
+ before_filter :login_required, :only => :destroy
4
+ before_filter :logout_required, :except => :destroy
4
5
 
5
- create do
6
- success do
7
- wants.html { redirect_to root_url }
8
- flash { t(:success) }
9
- end
10
- failure.flash_now { t(:failure) }
6
+ def new
7
+ @<%= user_session_singular_name %> = <%= user_session_class_name %>.new
11
8
  end
12
9
 
13
- destroy.success do
14
- flash { t(:success) }
15
- wants.html { redirect_to root_url }
10
+ def create
11
+ @<%= user_session_singular_name %> = <%= user_session_class_name %>.new(params[:<%= user_session_singular_name %>])
12
+ if @<%= user_session_singular_name %>.save
13
+ flash[:notice] = t(:success)
14
+ redirect_to root_url
15
+ else
16
+ render :action => 'new'
17
+ end
16
18
  end
17
19
 
18
- private
19
-
20
- def object
21
- @object ||= <%= user_session_class_name %>.find
20
+ def destroy
21
+ current_<%= user_session_singular_name %>.destroy
22
+ flash[:notice] = t(:success)
23
+ redirect_to root_url
22
24
  end
23
25
 
24
26
  end
@@ -2,42 +2,125 @@ require File.dirname(__FILE__) + '/../spec_helper'
2
2
  require 'authlogic/testing/test_unit_helpers' # put this in spec/spec_helper.rb
3
3
 
4
4
  describe <%= user_session_plural_class_name %>Controller do
5
- fixtures :all
5
+
6
6
  integrate_views
7
7
 
8
- describe "new action" do
8
+ def new_<%= user_singular_name %>(args = {})
9
+ Factory(:<%= user_singular_name %>, args)
10
+ end
11
+
12
+ describe "viewing the login page" do
13
+
14
+ context "when not logged in" do
15
+
16
+ it "should show the login page" do
17
+ get :new
18
+ response.should render_template(:new)
19
+ end
20
+
21
+ end
22
+
23
+ context "when logged in" do
24
+
25
+ it "should redirect to the home page" do
26
+ set_session_for new_<%= user_singular_name %>
27
+ get :new
28
+ response.should redirect_to(root_url)
29
+ end
9
30
 
10
- it "should render new template" do
11
- get :new
12
- response.should render_template(:new)
13
31
  end
14
32
 
15
33
  end
16
34
 
17
- describe "create action" do
35
+ describe "logging in" do
36
+
37
+ def login_with args
38
+ post :create, :<%= user_session_singular_name %> => { :login => "bob" }.merge(args)
39
+ end
40
+
41
+ before :each do
42
+ @<%= user_singular_name %> = new_<%= user_singular_name %>(:login => "bob", :password => "right")
43
+ <%= user_class_name %>.stub!(:find).and_return(@<%= user_singular_name %>)
44
+ end
45
+
46
+ context "with valid credentials" do
47
+
48
+ before :each do
49
+ login_with :password => "right"
50
+ end
51
+
52
+ it "should set a session for the <%= user_singular_name %>" do
53
+ controller.load_<%= user_session_singular_name %>
54
+ controller.current_<%= user_singular_name %>.should == @<%= user_singular_name %>
55
+ end
56
+
57
+ it "should be logged in" do
58
+ controller.load_<%= user_session_singular_name %>
59
+ controller.should be_logged_in
60
+ end
61
+
62
+ it "should redirect to the home page" do
63
+ response.should redirect_to(root_url)
64
+ end
18
65
 
19
- it "should render new template when authentication is invalid" do
20
- post :create, :<%= user_session_singular_name %> => { :login => "foo", :password => "wrong" }
21
- response.should render_template(:new)
22
- <%= user_session_class_name %>.find.should be_nil
23
66
  end
24
67
 
25
- it "should redirect when authentication is valid" do
26
- post :create, :<%= user_session_singular_name %> => { :login => "foo", :password => "secret" }
27
- response.should redirect_to(root_url)
28
- <%= user_session_class_name %>.find.should_not be_nil
29
- <%= user_session_class_name %>.find.user.should == <%= user_plural_name %>(:one)
68
+ context "with invalid credentials" do
69
+
70
+ before :each do
71
+ login_with :password => "wrong"
72
+ end
73
+
74
+ it "should not set a session" do
75
+ controller.load_<%= user_session_singular_name %>
76
+ controller.current_<%= user_singular_name %>.should be_nil
77
+ end
78
+
79
+ it "should not be logged in" do
80
+ controller.load_<%= user_session_singular_name %>
81
+ controller.should_not be_logged_in
82
+ end
83
+
84
+ it "should show the login page again" do
85
+ response.should render_template(:new)
86
+ end
87
+
30
88
  end
31
89
 
32
90
  end
33
91
 
34
- describe "destroy action" do
92
+ describe "logging out" do
93
+
94
+ context "when logged in" do
95
+
96
+ before :each do
97
+ set_session_for new_<%= user_singular_name %>
98
+ get :destroy
99
+ end
100
+
101
+ it "should redirect to the home page" do
102
+ response.should redirect_to(root_url)
103
+ end
104
+
105
+ it "should have destroyed the session" do
106
+ controller.load_<%= user_session_singular_name %>
107
+ controller.current_<%= user_session_singular_name %>.should be_nil
108
+ end
109
+
110
+ it "should not be logged in" do
111
+ controller.load_<%= user_session_singular_name %>
112
+ controller.should_not be_logged_in
113
+ end
114
+
115
+ end
116
+
117
+ context "when not yet logged in" do
118
+
119
+ it "should redirect to the login page" do
120
+ get :destroy
121
+ response.should redirect_to(login_url)
122
+ end
35
123
 
36
- it "should destroy user session" do
37
- set_session_for <%= user_plural_name %>(:one)
38
- delete :destroy
39
- <%= user_session_class_name %>.find.should be_nil
40
- response.should redirect_to(root_url)
41
124
  end
42
125
 
43
126
  end
@@ -2,44 +2,96 @@ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe <%= user_class_name %> do
4
4
 
5
- def new_<%= user_singular_name %>(attributes = {})
6
- attributes[:login] ||= 'foo'
7
- attributes[:password] ||= 'abc123'
8
- attributes[:password_confirmation] ||= attributes[:password]
9
- <%= user_class_name %>.new(attributes)
10
- end
5
+ context "when making a new <%= user_singular_name %>" do
11
6
 
12
- before(:each) do
13
- <%= user_class_name %>.delete_all
14
- end
7
+ def new_<%= user_singular_name %>(attrs = {})
8
+ Factory.build(:<%= user_singular_name %>, attrs)
9
+ end
15
10
 
16
- it "should be valid" do
17
- new_<%= user_singular_name %>.should be_valid
18
- end
11
+ before(:each) do
12
+ <%= user_class_name %>.delete_all
13
+ end
19
14
 
20
- it "should require login" do
21
- new_<%= user_singular_name %>(:login => '').should have_at_least(1).error_on(:login)
22
- end
15
+ it "should be valid" do
16
+ new_<%= user_singular_name %>.should be_valid
17
+ end
23
18
 
24
- it "should require password" do
25
- new_<%= user_singular_name %>(:password => '').should have_at_least(1).error_on(:password)
26
- end
19
+ it "should require login" do
20
+ new_<%= user_singular_name %>(:login => '').should have_at_least(1).error_on(:login)
21
+ end
27
22
 
28
- it "should validate uniqueness of login" do
29
- new_<%= user_singular_name %>(:login => 'uniquename').save!
30
- new_<%= user_singular_name %>(:login => 'uniquename').should have_at_least(1).error_on(:login)
31
- end
23
+ it "should require password" do
24
+ new_<%= user_singular_name %>(:password => '').should have_at_least(1).error_on(:password)
25
+ end
32
26
 
33
- it "should not allow odd characters in login" do
34
- new_<%= user_singular_name %>(:login => 'odd ^&(@)').should have_at_least(1).error_on(:login)
35
- end
27
+ it "should not allow odd characters in login" do
28
+ new_<%= user_singular_name %>(:login => 'odd ^&(@)').should have_at_least(1).error_on(:login)
29
+ end
30
+
31
+ it "should validate uniqueness of login" do
32
+ new_<%= user_singular_name %>(:login => 'uniquename').save!
33
+ new_<%= user_singular_name %>(:login => 'uniquename').should have_at_least(1).error_on(:login)
34
+ end
35
+
36
+ it "should require email" do
37
+ new_<%= user_singular_name %>(:email => '').should have_at_least(1).error_on(:email)
38
+ end
39
+
40
+ it "should validate uniqueness of email" do
41
+ new_<%= user_singular_name %>(:email => 'unique@email.com').save!
42
+ new_<%= user_singular_name %>(:email => 'unique@email.com').should have_at_least(1).error_on(:email)
43
+ end
44
+
45
+ it "should not allow bad formatted email addresses" do
46
+ new_<%= user_singular_name %>(:email => 'a@b').should have_at_least(1).error_on(:email)
47
+ end
48
+
49
+ it "should validate password is longer than 3 characters" do
50
+ new_<%= user_singular_name %>(:password => 'bad').should have_at_least(1).error_on(:password)
51
+ end
52
+
53
+ it "should require matching password confirmation" do
54
+ new_<%= user_singular_name %>(:password_confirmation => 'nonmatching').should have_at_least(1).error_on(:password)
55
+ end
36
56
 
37
- it "should validate password is longer than 3 characters" do
38
- new_<%= user_singular_name %>(:password => 'bad').should have_at_least(1).error_on(:password)
39
57
  end
40
58
 
41
- it "should require matching password confirmation" do
42
- new_<%= user_singular_name %>(:password_confirmation => 'nonmatching').should have_at_least(1).error_on(:password)
59
+ context "when editing a <%= user_singular_name %>" do
60
+
61
+ before :each do
62
+ @<%= user_singular_name %> = Factory(:<%= user_singular_name %>, :login => "bob", :password => "secret")
63
+ end
64
+
65
+ it "should not change the login" do
66
+ lambda {
67
+ @<%= user_singular_name %>.update_attributes(:login => "different")
68
+ }.should_not change(@<%= user_singular_name %>, :login)
69
+ end
70
+
71
+ it "should not change the password when no old password has been entered" do
72
+ lambda {
73
+ @<%= user_singular_name %>.update_attributes(:password => "newpassword", :password_confirmation => "newpassword")
74
+ }.should_not change(@<%= user_singular_name %>, :password)
75
+ end
76
+
77
+ it "should change the password when old password has been entered" do
78
+ lambda {
79
+ @<%= user_singular_name %>.update_attributes(:old_password => "secret", :password => "newpassword", :password_confirmation => "newpassword")
80
+ }.should change(@<%= user_singular_name %>, :password)
81
+ end
82
+
83
+ it "should change the email when old password has been entered" do
84
+ lambda {
85
+ @<%= user_singular_name %>.update_attributes(:old_password => "secret", :email => "new@email.com")
86
+ }.should change(@<%= user_singular_name %>, :email)
87
+ end
88
+
89
+ it "should not change the email when no old password has been entered" do
90
+ lambda {
91
+ @<%= user_singular_name %>.update_attributes(:email => "new@email.com")
92
+ }.should_not change(@<%= user_singular_name %>, :email)
93
+ end
94
+
43
95
  end
44
96
 
45
97
  end
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe <%= user_plural_class_name %>Controller do
4
- fixtures :all
4
+
5
5
  integrate_views
6
6
 
7
7
  describe "new action" do
@@ -3,20 +3,24 @@ require 'authlogic/testing/test_unit_helpers' # put this in test/test_helper.rb
3
3
 
4
4
  class <%= user_session_plural_class_name %>ControllerTest < ActionController::TestCase
5
5
 
6
+ def setup
7
+ @<%= user_singular_name %> = Factory(:<%= user_singular_name %>, :login => "bob", :password => "right")
8
+ end
9
+
6
10
  test "new action should render new template" do
7
11
  get :new
8
12
  assert_template 'new'
9
13
  end
10
14
 
11
15
  test "create action should create user session when succesful login" do
12
- post :create, :<%= user_session_singular_name %> => { :login => "foo", :password => "secret" }
16
+ post :create, :<%= user_session_singular_name %> => { :login => "bob", :password => "right" }
13
17
  assert <%= user_session_singular_name %> = <%= user_session_class_name %>.find
14
- assert_equal <%= user_plural_name %>(:foo), <%= user_session_singular_name %>.user
18
+ assert_equal @<%= user_singular_name %>, <%= user_session_singular_name %>.<%= user_singular_name %>
15
19
  assert_redirected_to root_url
16
20
  end
17
21
 
18
22
  test "create action should render new template when failed login" do
19
- post :create, :<%= user_session_singular_name %> => { :login => "foo", :password => "wrong" }
23
+ post :create, :<%= user_session_singular_name %> => { :login => "bob", :password => "wrong" }
20
24
  assert_template 'new'
21
25
  assert_nil <%= user_session_class_name %>.find
22
26
  end
@@ -27,6 +31,6 @@ class <%= user_session_plural_class_name %>ControllerTest < ActionController::Te
27
31
  delete :destroy
28
32
  assert_nil <%= user_session_class_name %>.find
29
33
  assert_redirected_to login_url
30
- end
34
+ end
31
35
 
32
36
  end
@@ -5,13 +5,13 @@ class <%= user_plural_class_name %>ControllerTest < ActionController::TestCase
5
5
  get :new
6
6
  assert_template 'new'
7
7
  end
8
-
8
+
9
9
  def test_create_invalid
10
10
  <%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
11
11
  post :create
12
12
  assert_template 'new'
13
13
  end
14
-
14
+
15
15
  def test_create_valid
16
16
  <%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
17
17
  post :create
@@ -1,3 +1,18 @@
1
1
  class <%= user_class_name %> < ActiveRecord::Base
2
- acts_as_authentic
2
+ acts_as_authentic :session_class => "<%= user_session_class_name %>"
3
+
4
+ attr_accessible :login, :email, :password, :password_confirmation, :old_password
5
+
6
+ validate_on_update :old_password_entered
7
+
8
+ def login=(str)
9
+ write_attribute(:login, str) if new_record?
10
+ end
11
+
12
+ private
13
+
14
+ def old_password_entered
15
+
16
+ end
17
+
3
18
  end
@@ -1,13 +1,38 @@
1
- class <%= user_plural_class_name %>Controller < ResourceController::Base
1
+ class <%= user_plural_class_name %>Controller < ApplicationController
2
2
 
3
- actions :new, :create
3
+ before_filter :logout_required, :only => [ :new, :create ]
4
+ before_filter :login_required, :only => [ :show, :edit, :update ]
4
5
 
5
- create do
6
- success do
7
- flash { t(:success) }
8
- wants.html { redirect_to root_url }
6
+ def new
7
+ @<%= user_singular_name %> = <%= user_class_name %>.new
8
+ end
9
+
10
+ def create
11
+ @<%= user_singular_name %> = <%= user_class_name %>.new(params[:<%= user_singular_name %>])
12
+ if @<%= user_singular_name %>.save
13
+ flash[:notice] = t(:success)
14
+ redirect_to <%= user_singular_name %>_url
15
+ else
16
+ render :action => 'new'
17
+ end
18
+ end
19
+
20
+ def show
21
+ @<%= user_singular_name %> = current_<%= user_singular_name %>
22
+ end
23
+
24
+ def edit
25
+ @<%= user_singular_name %> = current_<%= user_singular_name %>
26
+ end
27
+
28
+ def update
29
+ @<%= user_singular_name %> = current_<%= user_singular_name %>
30
+ if @<%= user_singular_name %>.update_attributes(params[:<%= user_singular_name %>])
31
+ flash[:notice] = t(:success)
32
+ redirect_to <%= user_singular_name %>_url
33
+ else
34
+ render :action => 'new'
9
35
  end
10
- failure.flash_now { t(:failure) }
11
36
  end
12
37
 
13
38
  end
@@ -0,0 +1,21 @@
1
+ - title t(:title)
2
+
3
+ - form_for @<%= user_singular_name %> do |f|
4
+ = f.error_messages
5
+ - f.fieldset do
6
+ - f.required_field :email
7
+ - f.field do
8
+ = f.required :old_password
9
+ = f.password_field :old_password
10
+ - f.field do
11
+ = f.label :password
12
+ = f.password_field :password
13
+ - f.field do
14
+ = f.label :password_confirmation
15
+ = f.password_field :password_confirmation
16
+ - f.field do
17
+ %label &nbsp;
18
+ = f.submit t(:submit)
19
+
20
+ %ol.actions
21
+ %li.show= link_to t(:show), <%= user_singular_name %>_path
@@ -1,9 +1,9 @@
1
1
  - title t(:title)
2
2
 
3
- - form_for @<%= user_session_singular_name %>, :url => object_path do |f|
3
+ - form_for @<%= user_session_singular_name %>, :url => <%= user_session_singular_name %>_path do |f|
4
4
  = f.error_messages
5
5
  - f.fieldset do
6
- - f.field :login
6
+ - f.required_field :login
7
7
  - f.field do
8
8
  = f.required :password
9
9
  = f.password_field :password
@@ -0,0 +1,19 @@
1
+ - title t(:title)
2
+
3
+ - form_for @<%= user_singular_name %> do |f|
4
+ = f.error_messages
5
+ - f.fieldset do
6
+ - f.required_field :login
7
+ - f.required_field :email
8
+ - f.field do
9
+ = f.required :password
10
+ = f.password_field :password
11
+ - f.field do
12
+ = f.required :password_confirmation
13
+ = f.password_field :password_confirmation
14
+ - f.field do
15
+ %label &nbsp;
16
+ = f.submit t(:submit)
17
+
18
+ %ol.actions
19
+ %li.login= link_to t(:login), login_path
@@ -0,0 +1,15 @@
1
+ - title t(:title)
2
+
3
+ - definition_list_for @<%= user_singular_name %> do |dl|
4
+ - dl.show_h :login
5
+ - dl.show_h :email
6
+ - dl.show_h :login_count
7
+ - dl.show_h :last_request_at
8
+ - dl.show_h :current_logint_at
9
+ - dl.show_h :last_login_at
10
+ - dl.show_h :current_login_ip
11
+ - dl.show_h :last_login_ip
12
+
13
+ %ol.actions
14
+ %li.edit= link_to t(:edit), edit_<%= user_singular_name %>_path
15
+ %li.logout= link_to t(:logout), logout_path
@@ -1,9 +1,10 @@
1
1
  - title t(:title)
2
2
 
3
- - form_for @<%= user_singular_name %>, :url => collection_path do |f|
3
+ - form_for @<%= user_singular_name %>, :url => <%= user_session_singular_name %>_path do |f|
4
4
  = f.error_messages
5
5
  - f.fieldset do
6
- - f.field :login
6
+ - f.required_field :login
7
+ - f.required_field :email
7
8
  - f.field do
8
9
  = f.required :password
9
10
  = f.password_field :password
@@ -136,18 +136,17 @@ class PizzaScaffoldGenerator < Rails::Generator::Base
136
136
  def controller_methods(dir_name)
137
137
  controller_actions.map do |action|
138
138
  read_template("#{dir_name}/#{action}.rb")
139
- end.join(" \n").strip
139
+ end.join("\n").strip
140
140
  end
141
141
 
142
- def render_form(url)
142
+ def render_form
143
143
  if form_partial?
144
144
  if options[:erb]
145
- "<%= render :partial => 'form' %>"
145
+ "<%= render 'form' %>"
146
146
  else
147
- "= render :partial => 'form', :locals => { :form_url => #{url} }"
147
+ "= render \"form\""
148
148
  end
149
149
  else
150
- (options[:erb] ? "" : "- form_url = #{url}\n") +
151
150
  read_template("views/#{view_language}/_form.html.#{view_language}")
152
151
  end
153
152
  end
@@ -1,4 +1,16 @@
1
- create do
2
- success.flash { t(:success, :model => <%= class_name %>.human_name) }
3
- failure.flash_now { t(:failure, :model => <%= class_name %>.human_name) }
1
+ # POST /<%= plural_name %>
2
+ # POST /<%= plural_name %>.xml
3
+ def create
4
+ @<%= singular_name %> = <%= class_name %>.new(params[:<%= singular_name %>])
5
+
6
+ respond_to do |format|
7
+ if @<%= singular_name %>.save
8
+ flash[:notice] = '<%= class_name.titleize %> was successfully created.'
9
+ format.html { redirect_to(<%= item_path('url') %>) }
10
+ format.xml { render :xml => @<%= singular_name %>, :status => :created, :location => @<%= singular_name %> }
11
+ else
12
+ format.html { render :new }
13
+ format.xml { render :xml => @<%= singular_name %>.errors, :status => :unprocessable_entity }
14
+ end
15
+ end
4
16
  end
@@ -1,4 +1,11 @@
1
- destroy do
2
- success.flash { t(:success, :model => <%= class_name %>.human_name) }
3
- failure.flash { t(:failure, :model => <%= class_name %>.human_name) }
1
+ # DELETE /<%= plural_name %>/1
2
+ # DELETE /<%= plural_name %>/1.xml
3
+ def destroy
4
+ @<%= singular_name %> = <%= class_name %>.find(params[:id])
5
+ @<%= singular_name %>.destroy
6
+
7
+ respond_to do |format|
8
+ format.html { redirect_to(<%= plural_name %>_url) }
9
+ format.xml { head :ok }
10
+ end
4
11
  end
@@ -0,0 +1,4 @@
1
+ # GET /<%= plural_name %>/1/edit
2
+ def edit
3
+ @<%= singular_name %> = <%= class_name %>.find(params[:id])
4
+ end
@@ -1,3 +1,10 @@
1
- def collection
2
- @collection ||= end_of_association_chain.paginate(:page => params[:page])
1
+ # GET /<%= plural_name %>
2
+ # GET /<%= plural_name %>.xml
3
+ def index
4
+ @<%= plural_name %> = <%= class_name %>.paginate(:page => params[:page])
5
+
6
+ respond_to do |format|
7
+ format.html # index.html.<%= view_language %>
8
+ format.xml { render :xml => @<%= plural_name %> }
9
+ end
3
10
  end
@@ -0,0 +1,10 @@
1
+ # GET /<%= plural_name %>/new
2
+ # GET /<%= plural_name %>/new.xml
3
+ def new
4
+ @<%= singular_name %> = <%= class_name %>.new
5
+
6
+ respond_to do |format|
7
+ format.html # new.html.<%= view_language %>
8
+ format.xml { render :xml => @<%= singular_name %> }
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # GET /<%= plural_name %>/1
2
+ # GET /<%= plural_name %>/1.xml
3
+ def show
4
+ @<%= singular_name %> = <%= class_name %>.find(params[:id])
5
+
6
+ respond_to do |format|
7
+ format.html # show.html.<%= view_language %>
8
+ format.xml { render :xml => @<%= singular_name %> }
9
+ end
10
+ end
@@ -1,4 +1,16 @@
1
- update do
2
- success.flash { t(:success, :model => <%= class_name %>.human_name) }
3
- failure.flash_now { t(:failure, :model => <%= class_name %>.human_name) }
1
+ # PUT /<%= plural_name %>/1
2
+ # PUT /<%= plural_name %>/1.xml
3
+ def update
4
+ @<%= singular_name %> = <%= class_name %>.find(params[:id])
5
+
6
+ respond_to do |format|
7
+ if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
8
+ flash[:notice] = '<%= class_name.titleize %> was successfully updated.'
9
+ format.html { redirect_to(<%= item_path('url') %>) }
10
+ format.xml { head :ok }
11
+ else
12
+ format.html { render :edit }
13
+ format.xml { render :xml => @<%= singular_name %>.errors, :status => :unprocessable_entity }
14
+ end
15
+ end
4
16
  end