edit_mode 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +23 -0
- data/.rspec +1 -0
- data/Gemfile +29 -0
- data/Guardfile +19 -0
- data/LICENSE +22 -0
- data/README.md +135 -0
- data/Rakefile +8 -0
- data/edit_mode.gemspec +31 -0
- data/lib/assets/javascripts/edit_mode/best_in_place.js.coffee +25 -0
- data/lib/assets/javascripts/edit_mode/best_in_place.js.coffee~ +26 -0
- data/lib/assets/javascripts/edit_mode/edit_mode_group.js.coffee +43 -0
- data/lib/assets/javascripts/edit_mode/initial_auto_hide.js.coffee +8 -0
- data/lib/assets/javascripts/edit_mode/make_modal.js.coffee +28 -0
- data/lib/assets/javascripts/edit_mode/show_only_in_edit_mode.js.coffee +22 -0
- data/lib/assets/javascripts/edit_mode/tool_buttons.js.coffee +21 -0
- data/lib/assets/javascripts/edit_mode.js +2 -0
- data/lib/assets/stylesheets/edit_mode/initial_auto_hide.css.sass +3 -0
- data/lib/assets/stylesheets/edit_mode/modal.css.sass +17 -0
- data/lib/assets/stylesheets/edit_mode.css +4 -0
- data/lib/assets/stylesheets/edit_mode.css~ +4 -0
- data/lib/edit_mode/engine.rb +7 -0
- data/lib/edit_mode/helper.rb +19 -0
- data/lib/edit_mode/railtie.rb +7 -0
- data/lib/edit_mode/version.rb +3 -0
- data/lib/edit_mode.rb +9 -0
- data/spec/helpers/edit_mode_helpers_spec.rb +26 -0
- data/spec/integration/buttons_spec.rb +69 -0
- data/spec/integration/show_only_in_edit_mode_spec.rb +24 -0
- data/spec/spec_helper.rb +22 -0
- data/test_app/.gitignore +15 -0
- data/test_app/Gemfile +56 -0
- data/test_app/README.md +135 -0
- data/test_app/Rakefile +7 -0
- data/test_app/app/assets/images/rails.png +0 -0
- data/test_app/app/assets/images/screenshot.png +0 -0
- data/test_app/app/assets/javascripts/activate_best_in_place.js +4 -0
- data/test_app/app/assets/javascripts/application.js +18 -0
- data/test_app/app/assets/stylesheets/#application.css# +14 -0
- data/test_app/app/assets/stylesheets/application.css +14 -0
- data/test_app/app/assets/stylesheets/modifications.css.sass +9 -0
- data/test_app/app/assets/stylesheets/nifty.css +79 -0
- data/test_app/app/controllers/application_controller.rb +3 -0
- data/test_app/app/controllers/root_controller.rb +11 -0
- data/test_app/app/controllers/users_controller.rb +44 -0
- data/test_app/app/helpers/application_helper.rb +2 -0
- data/test_app/app/helpers/error_messages_helper.rb +23 -0
- data/test_app/app/helpers/layout_helper.rb +22 -0
- data/test_app/app/helpers/users_helper.rb +2 -0
- data/test_app/app/mailers/.gitkeep +0 -0
- data/test_app/app/models/.gitkeep +0 -0
- data/test_app/app/models/user.rb +3 -0
- data/test_app/app/views/layouts/application.html.erb +19 -0
- data/test_app/app/views/users/_form.html.erb +16 -0
- data/test_app/app/views/users/edit.html.erb +8 -0
- data/test_app/app/views/users/index.html.erb +29 -0
- data/test_app/app/views/users/index.html.erb~ +21 -0
- data/test_app/app/views/users/new.html.erb +5 -0
- data/test_app/app/views/users/show.html.erb +54 -0
- data/test_app/app/views/users/show.html.erb~ +50 -0
- data/test_app/config/application.rb +59 -0
- data/test_app/config/boot.rb +6 -0
- data/test_app/config/database.yml +25 -0
- data/test_app/config/environment.rb +5 -0
- data/test_app/config/environments/development.rb +37 -0
- data/test_app/config/environments/production.rb +67 -0
- data/test_app/config/environments/test.rb +37 -0
- data/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test_app/config/initializers/inflections.rb +15 -0
- data/test_app/config/initializers/mime_types.rb +5 -0
- data/test_app/config/initializers/secret_token.rb +7 -0
- data/test_app/config/initializers/session_store.rb +8 -0
- data/test_app/config/initializers/wrap_parameters.rb +14 -0
- data/test_app/config/locales/en.yml +5 -0
- data/test_app/config/routes.rb +62 -0
- data/test_app/config.ru +4 -0
- data/test_app/db/migrate/20120607231941_create_users.rb +14 -0
- data/test_app/db/schema.rb +24 -0
- data/test_app/db/seeds.rb +7 -0
- data/test_app/lib/assets/.gitkeep +0 -0
- data/test_app/lib/tasks/.gitkeep +0 -0
- data/test_app/public/404.html +26 -0
- data/test_app/public/422.html +26 -0
- data/test_app/public/500.html +25 -0
- data/test_app/public/favicon.ico +0 -0
- data/test_app/public/robots.txt +5 -0
- data/test_app/public/stylesheets/application.css +75 -0
- data/test_app/script/rails +6 -0
- data/test_app/test/fixtures/users.yml +9 -0
- data/test_app/test/functional/users_controller_test.rb +54 -0
- data/test_app/test/unit/user_test.rb +7 -0
- data/test_app/vendor/assets/javascripts/.gitkeep +0 -0
- data/test_app/vendor/assets/stylesheets/.gitkeep +0 -0
- data/test_app/vendor/plugins/.gitkeep +0 -0
- metadata +232 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "show only in edit mode span tags", js: true do
|
4
|
+
|
5
|
+
before do
|
6
|
+
visit user_path( User.first )
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should not be visible when not in edit mode" do
|
10
|
+
page.should_not have_selector( ".show_only_in_edit_mode", visible: true )
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should be visible in edit mode" do
|
14
|
+
click_on 'edit'
|
15
|
+
page.should have_selector( ".show_only_in_edit_mode", visible: true )
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be invisible after exiting the edit mode" do
|
19
|
+
click_on 'edit'
|
20
|
+
click_on 'cancel'
|
21
|
+
page.should_not have_selector( ".show_only_in_edit_mode", visible: true )
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path('../../test_app/config/environment', __FILE__)
|
5
|
+
|
6
|
+
require "rspec/rails"
|
7
|
+
require "nokogiri"
|
8
|
+
|
9
|
+
# Load support files
|
10
|
+
#Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each{|f| require f}
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
|
14
|
+
require 'rspec/expectations'
|
15
|
+
|
16
|
+
config.include RSpec::Matchers
|
17
|
+
# config.include EditMode::TestHelpers
|
18
|
+
|
19
|
+
config.mock_with :rspec
|
20
|
+
end
|
21
|
+
|
22
|
+
# Capybara.default_wait_time = 5
|
data/test_app/.gitignore
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile ~/.gitignore_global
|
6
|
+
|
7
|
+
# Ignore bundler config
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3
|
12
|
+
|
13
|
+
# Ignore all logfiles and tempfiles.
|
14
|
+
/log/*.log
|
15
|
+
/tmp
|
data/test_app/Gemfile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '3.2.3'
|
4
|
+
|
5
|
+
# Bundle edge Rails instead:
|
6
|
+
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem 'sqlite3'
|
10
|
+
end
|
11
|
+
group :production do
|
12
|
+
gem 'pg'
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
# Gems used only for assets and not required
|
17
|
+
# in production environments by default.
|
18
|
+
group :assets do
|
19
|
+
gem 'sass-rails', '~> 3.2.3'
|
20
|
+
gem 'coffee-rails', '~> 3.2.1'
|
21
|
+
|
22
|
+
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
23
|
+
gem 'therubyracer', :platform => :ruby
|
24
|
+
|
25
|
+
gem 'uglifier', '>= 1.0.3'
|
26
|
+
end
|
27
|
+
|
28
|
+
gem 'jquery-rails'
|
29
|
+
gem 'jquery-ui-rails'
|
30
|
+
|
31
|
+
group :development do
|
32
|
+
gem 'nifty-generators'
|
33
|
+
end
|
34
|
+
|
35
|
+
# To use ActiveModel has_secure_password
|
36
|
+
# gem 'bcrypt-ruby', '~> 3.0.0'
|
37
|
+
|
38
|
+
# To use Jbuilder templates for JSON
|
39
|
+
# gem 'jbuilder'
|
40
|
+
|
41
|
+
# Use unicorn as the app server
|
42
|
+
# gem 'unicorn'
|
43
|
+
|
44
|
+
# Deploy with Capistrano
|
45
|
+
# gem 'capistrano'
|
46
|
+
|
47
|
+
# To use debugger
|
48
|
+
# gem 'ruby-debug19', :require => 'ruby-debug'
|
49
|
+
|
50
|
+
gem "mocha", :group => :test
|
51
|
+
|
52
|
+
# Edit Mode (This is the gem to demonstrate here.)
|
53
|
+
gem 'edit_mode', git: 'git://github.com/fiedl/edit_mode.git'
|
54
|
+
|
55
|
+
# In-place editing (To show that this gem integrates best_in_place out of the box.)
|
56
|
+
gem 'best_in_place'
|
data/test_app/README.md
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
# EditMode
|
2
|
+
|
3
|
+
<img src="https://github.com/fiedl/edit_mode/raw/master/test_app/app/assets/images/screenshot.png" height="300" align="right" vspace="20" hspace="20" />
|
4
|
+
|
5
|
+
*edit_mode* is a *ruby on rails gem* that allows you to toggle an edit mode on a normal show view.
|
6
|
+
Think of it as a grouped in-place editing.
|
7
|
+
This also toggles [best_in_place](https://github.com/bernat/best_in_place) fields.
|
8
|
+
|
9
|
+
The edit mode is activated by pressing an 'edit' button on a show view. This shows additional editing tools
|
10
|
+
and switches on the best_in_place form fields. When editing is finished, use 'save' or 'cancel' buttons to
|
11
|
+
quit the edit mode and return to a normal show view.
|
12
|
+
Several editing groups per page are supported. Thus, you can have several 'boxes' to edit on a page.
|
13
|
+
|
14
|
+
## Demo
|
15
|
+
|
16
|
+
You might want to have a look at [this demo app at heroku](http://edit-mode-test-app.herokuapp.com/).
|
17
|
+
|
18
|
+
The [code of this demo app can be found here](https://github.com/fiedl/edit_mode/tree/master/test_app).
|
19
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
THIS IS NOT READY, YET.
|
23
|
+
|
24
|
+
Add this line to your application's Gemfile:
|
25
|
+
|
26
|
+
gem 'edit_mode'
|
27
|
+
|
28
|
+
And then execute:
|
29
|
+
|
30
|
+
$ bundle
|
31
|
+
|
32
|
+
Or install it yourself as:
|
33
|
+
|
34
|
+
$ gem install edit_mode
|
35
|
+
|
36
|
+
TODO: Include css and js.
|
37
|
+
|
38
|
+
### Include Assets
|
39
|
+
|
40
|
+
In `app/assets/javascripts/application.js`, add:
|
41
|
+
|
42
|
+
```javascript
|
43
|
+
//= require edit_mode
|
44
|
+
```
|
45
|
+
|
46
|
+
In `app/assets/stylesheets/application.css`, add:
|
47
|
+
|
48
|
+
```css
|
49
|
+
/*
|
50
|
+
*...
|
51
|
+
*= require edit_mode
|
52
|
+
*/
|
53
|
+
```
|
54
|
+
|
55
|
+
## Usage
|
56
|
+
|
57
|
+
### Basic View
|
58
|
+
|
59
|
+
For a basic example, see: https://github.com/fiedl/edit_mode/blob/master/test_app/app/views/users/show.html.erb
|
60
|
+
|
61
|
+
### edit_mode_group
|
62
|
+
|
63
|
+
The edit mode is toggled within a `<span class="edit_mode_group"></span>`. The buttons to 'edit', 'save' and 'cancel' should also be placed inside this span.
|
64
|
+
|
65
|
+
You can also have several edit_mode_group spans on a page, as shown in the demo app.
|
66
|
+
|
67
|
+
### Tool Buttons
|
68
|
+
|
69
|
+
To enter and exit the edit mode, use buttons 'edit', 'save' and 'cancel'. These can be anchors, images, et cetera. They only have to have the correct css classes:
|
70
|
+
|
71
|
+
```html
|
72
|
+
<span class="edit_mode_group">
|
73
|
+
<a class="edit_button" href="#">edit</a>
|
74
|
+
<a class="save_button" href="#">save</a>
|
75
|
+
<a class="cancel_button" href="#">cancel</a>
|
76
|
+
...
|
77
|
+
</span>
|
78
|
+
```
|
79
|
+
|
80
|
+
### show_only_in_edit_mode
|
81
|
+
|
82
|
+
Within the edit_mode_group span, you may place certain elements that should only be shown when in edit mode. You can use this for 'add' buttons or 'destroy' buttons.
|
83
|
+
|
84
|
+
```html
|
85
|
+
<span class="edit_mode_group">
|
86
|
+
...
|
87
|
+
<span class="show_only_in_edit_mode">
|
88
|
+
<a href="#">add</a>
|
89
|
+
</span>
|
90
|
+
</span>
|
91
|
+
```
|
92
|
+
|
93
|
+
The same, the other way round:
|
94
|
+
|
95
|
+
```html
|
96
|
+
<span class="edit_mode_group">
|
97
|
+
...
|
98
|
+
<span class="do_not_show_in_edit_mode">
|
99
|
+
<img src="..." alt="This picture is not shown in edit mode." />
|
100
|
+
</span>
|
101
|
+
</span>
|
102
|
+
```
|
103
|
+
|
104
|
+
### best_in_place
|
105
|
+
|
106
|
+
In the edit_mode_group span, all [best_in_place](https://github.com/bernat/best_in_place) elements are toggled as well.
|
107
|
+
|
108
|
+
### '.editable' Triggers
|
109
|
+
|
110
|
+
If you need custom behaviour inside the edit_mode_group span, you can use these triggers: For all elements of the class `.editable`, the events `edit`, `save` and `cancel` are triggered, when entering or exiting edit mode.
|
111
|
+
|
112
|
+
```html
|
113
|
+
<span class="edit_mode_group">
|
114
|
+
...
|
115
|
+
<span class="editable custom_element">Test</span>
|
116
|
+
</span>
|
117
|
+
```
|
118
|
+
|
119
|
+
Bind the event via JavaScript, e.g. with jQuery:
|
120
|
+
|
121
|
+
```coffee
|
122
|
+
jQuery ->
|
123
|
+
$( ".custom_element" ).bind( "edit", ->
|
124
|
+
alert( "This element has just entered edit mode." )
|
125
|
+
)
|
126
|
+
```
|
127
|
+
|
128
|
+
## Contributing
|
129
|
+
|
130
|
+
1. Fork it
|
131
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
132
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
133
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
134
|
+
5. Create new Pull Request
|
135
|
+
|
data/test_app/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
TestApp::Application.load_tasks
|
Binary file
|
Binary file
|
@@ -0,0 +1,18 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery-ui
|
15
|
+
//= require jquery_ujs
|
16
|
+
//= require best_in_place
|
17
|
+
//= require edit_mode
|
18
|
+
//= require_tree .
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
14
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require edit_mode
|
12
|
+
*= require_self
|
13
|
+
*= require_tree .
|
14
|
+
*/
|
@@ -0,0 +1,79 @@
|
|
1
|
+
body {
|
2
|
+
background-color: #4B7399;
|
3
|
+
font-family: Verdana, Helvetica, Arial;
|
4
|
+
font-size: 14px;
|
5
|
+
}
|
6
|
+
|
7
|
+
a img {
|
8
|
+
border: none;
|
9
|
+
}
|
10
|
+
|
11
|
+
a {
|
12
|
+
color: #0000FF;
|
13
|
+
}
|
14
|
+
|
15
|
+
.clear {
|
16
|
+
clear: both;
|
17
|
+
height: 0;
|
18
|
+
overflow: hidden;
|
19
|
+
}
|
20
|
+
|
21
|
+
#container {
|
22
|
+
width: 75%;
|
23
|
+
margin: 0 auto;
|
24
|
+
background-color: #FFF;
|
25
|
+
padding: 20px 40px;
|
26
|
+
border: solid 1px black;
|
27
|
+
margin-top: 20px;
|
28
|
+
}
|
29
|
+
|
30
|
+
#flash_notice, #flash_error, #flash_alert {
|
31
|
+
padding: 5px 8px;
|
32
|
+
margin: 10px 0;
|
33
|
+
}
|
34
|
+
|
35
|
+
#flash_notice {
|
36
|
+
background-color: #CFC;
|
37
|
+
border: solid 1px #6C6;
|
38
|
+
}
|
39
|
+
|
40
|
+
#flash_error, #flash_alert {
|
41
|
+
background-color: #FCC;
|
42
|
+
border: solid 1px #C66;
|
43
|
+
}
|
44
|
+
|
45
|
+
.field_with_errors {
|
46
|
+
display: inline;
|
47
|
+
}
|
48
|
+
|
49
|
+
.error_messages {
|
50
|
+
width: 400px;
|
51
|
+
border: 2px solid #CF0000;
|
52
|
+
padding: 0px;
|
53
|
+
padding-bottom: 12px;
|
54
|
+
margin-bottom: 20px;
|
55
|
+
background-color: #f0f0f0;
|
56
|
+
font-size: 12px;
|
57
|
+
}
|
58
|
+
|
59
|
+
.error_messages h2 {
|
60
|
+
text-align: left;
|
61
|
+
font-weight: bold;
|
62
|
+
padding: 5px 10px;
|
63
|
+
font-size: 12px;
|
64
|
+
margin: 0;
|
65
|
+
background-color: #c00;
|
66
|
+
color: #fff;
|
67
|
+
}
|
68
|
+
|
69
|
+
.error_messages p {
|
70
|
+
margin: 8px 10px;
|
71
|
+
}
|
72
|
+
|
73
|
+
.error_messages ul {
|
74
|
+
margin-bottom: 0;
|
75
|
+
}
|
76
|
+
|
77
|
+
form .field, form .actions {
|
78
|
+
margin: 12px 0;
|
79
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class UsersController < ApplicationController
|
2
|
+
def index
|
3
|
+
@users = User.all
|
4
|
+
end
|
5
|
+
|
6
|
+
def show
|
7
|
+
@user = User.find(params[:id])
|
8
|
+
end
|
9
|
+
|
10
|
+
def new
|
11
|
+
@user = User.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
@user = User.new(params[:user])
|
16
|
+
if @user.save
|
17
|
+
redirect_to @user, :notice => "Successfully created user."
|
18
|
+
else
|
19
|
+
render :action => 'new'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def edit
|
24
|
+
@user = User.find(params[:id])
|
25
|
+
end
|
26
|
+
|
27
|
+
def update
|
28
|
+
@user = User.find(params[:id])
|
29
|
+
if @user.update_attributes(params[:user])
|
30
|
+
respond_to do |format|
|
31
|
+
format.json { respond_with_bip( @user ) }
|
32
|
+
format.html { redirect_to @user, :notice => "Successfully updated user." }
|
33
|
+
end
|
34
|
+
else
|
35
|
+
render :action => 'edit'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def destroy
|
40
|
+
@user = User.find(params[:id])
|
41
|
+
@user.destroy
|
42
|
+
redirect_to users_url, :notice => "Successfully destroyed user."
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ErrorMessagesHelper
|
2
|
+
# Render error messages for the given objects. The :message and :header_message options are allowed.
|
3
|
+
def error_messages_for(*objects)
|
4
|
+
options = objects.extract_options!
|
5
|
+
options[:header_message] ||= I18n.t(:"activerecord.errors.header", :default => "Invalid Fields")
|
6
|
+
options[:message] ||= I18n.t(:"activerecord.errors.message", :default => "Correct the following errors and try again.")
|
7
|
+
messages = objects.compact.map { |o| o.errors.full_messages }.flatten
|
8
|
+
unless messages.empty?
|
9
|
+
content_tag(:div, :class => "error_messages") do
|
10
|
+
list_items = messages.map { |msg| content_tag(:li, msg) }
|
11
|
+
content_tag(:h2, options[:header_message]) + content_tag(:p, options[:message]) + content_tag(:ul, list_items.join.html_safe)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module FormBuilderAdditions
|
17
|
+
def error_messages(options = {})
|
18
|
+
@template.error_messages_for(@object, options)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
ActionView::Helpers::FormBuilder.send(:include, ErrorMessagesHelper::FormBuilderAdditions)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# These helper methods can be called in your template to set variables to be used in the layout
|
2
|
+
# This module should be included in all views globally,
|
3
|
+
# to do so you may need to add this line to your ApplicationController
|
4
|
+
# helper :layout
|
5
|
+
module LayoutHelper
|
6
|
+
def title(page_title, show_title = true)
|
7
|
+
content_for(:title) { h(page_title.to_s) }
|
8
|
+
@show_title = show_title
|
9
|
+
end
|
10
|
+
|
11
|
+
def show_title?
|
12
|
+
@show_title
|
13
|
+
end
|
14
|
+
|
15
|
+
def stylesheet(*args)
|
16
|
+
content_for(:head) { stylesheet_link_tag(*args) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def javascript(*args)
|
20
|
+
content_for(:head) { javascript_include_tag(*args) }
|
21
|
+
end
|
22
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
|
5
|
+
<%= stylesheet_link_tag "application" %>
|
6
|
+
<%= javascript_include_tag :application %>
|
7
|
+
<%= csrf_meta_tag %>
|
8
|
+
<%= yield(:head) %>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
<div id="container">
|
12
|
+
<% flash.each do |name, msg| %>
|
13
|
+
<%= content_tag :div, msg, :id => "flash_#{name}" %>
|
14
|
+
<% end %>
|
15
|
+
<%= content_tag :h1, yield(:title) if show_title? %>
|
16
|
+
<%= yield %>
|
17
|
+
</div>
|
18
|
+
</body>
|
19
|
+
</html>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<%= form_for @user do |f| %>
|
2
|
+
<%= f.error_messages %>
|
3
|
+
<p>
|
4
|
+
<%= f.label :first_name %><br />
|
5
|
+
<%= f.text_field :first_name %>
|
6
|
+
</p>
|
7
|
+
<p>
|
8
|
+
<%= f.label :last_name %><br />
|
9
|
+
<%= f.text_field :last_name %>
|
10
|
+
</p>
|
11
|
+
<p>
|
12
|
+
<%= f.label :date_of_birth %><br />
|
13
|
+
<%= f.date_select :date_of_birth %>
|
14
|
+
</p>
|
15
|
+
<p><%= f.submit %></p>
|
16
|
+
<% end %>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<% title "Users" %>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
This demo app shows how <a href="https://github.com/fiedl/edit_mode" target="_blank">edit_mode</a> looks like.
|
5
|
+
</p>
|
6
|
+
<p>
|
7
|
+
Just go to the 'show' page of a user and edit his profile there. (If no user exists, you will have to create one first.)
|
8
|
+
</p>
|
9
|
+
|
10
|
+
|
11
|
+
<table>
|
12
|
+
<tr>
|
13
|
+
<th>First Name</th>
|
14
|
+
<th>Last Name</th>
|
15
|
+
<th>Date Of Birth</th>
|
16
|
+
</tr>
|
17
|
+
<% for user in @users %>
|
18
|
+
<tr>
|
19
|
+
<td><%= user.first_name %></td>
|
20
|
+
<td><%= user.last_name %></td>
|
21
|
+
<td><%= user.date_of_birth %></td>
|
22
|
+
<td><%= link_to "Show", user %></td>
|
23
|
+
<td><%= link_to "Edit", edit_user_path(user) %></td>
|
24
|
+
<td><%= link_to "Destroy", user, :confirm => 'Are you sure?', :method => :delete %></td>
|
25
|
+
</tr>
|
26
|
+
<% end %>
|
27
|
+
</table>
|
28
|
+
|
29
|
+
<p><%= link_to "New User", new_user_path %></p>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<% title "Users" %>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<th>First Name</th>
|
6
|
+
<th>Last Name</th>
|
7
|
+
<th>Date Of Birth</th>
|
8
|
+
</tr>
|
9
|
+
<% for user in @users %>
|
10
|
+
<tr>
|
11
|
+
<td><%= user.first_name %></td>
|
12
|
+
<td><%= user.last_name %></td>
|
13
|
+
<td><%= user.date_of_birth %></td>
|
14
|
+
<td><%= link_to "Show", user %></td>
|
15
|
+
<td><%= link_to "Edit", edit_user_path(user) %></td>
|
16
|
+
<td><%= link_to "Destroy", user, :confirm => 'Are you sure?', :method => :delete %></td>
|
17
|
+
</tr>
|
18
|
+
<% end %>
|
19
|
+
</table>
|
20
|
+
|
21
|
+
<p><%= link_to "New User", new_user_path %></p>
|