edifice-forms 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +22 -3
- data/Rakefile +6 -0
- data/app/assets/javascripts/edifice-forms/jquery-escape.js +15 -0
- data/app/assets/javascripts/edifice-forms/rails_form.js +1 -1
- data/app/assets/javascripts/edifice-forms/show-errors.js +9 -1
- data/edifice-forms.gemspec +7 -1
- data/lib/edifice-forms/responder.rb +4 -3
- data/lib/edifice-forms/version.rb +1 -1
- data/spec/error_handling_spec.rb +54 -0
- data/spec/form_model_spec.rb +25 -0
- data/spec/rails3.1/app/assets/images/rails.png +0 -0
- data/spec/rails3.1/app/assets/javascripts/application.js +10 -0
- data/spec/rails3.1/app/assets/javascripts/test/base.js +11 -0
- data/spec/rails3.1/app/assets/javascripts/vendor/jquery-pjax.js +264 -0
- data/spec/rails3.1/app/assets/stylesheets/application.css +7 -0
- data/spec/rails3.1/app/controllers/application_controller.rb +3 -0
- data/spec/rails3.1/app/controllers/users_controller.rb +18 -0
- data/spec/rails3.1/app/models/user.rb +15 -0
- data/spec/rails3.1/app/views/layouts/application.html.erb +14 -0
- data/spec/rails3.1/app/views/users/new.html.erb +15 -0
- data/spec/rails3.1/config/application.rb +55 -0
- data/spec/rails3.1/config/boot.rb +6 -0
- data/spec/rails3.1/config/environment.rb +5 -0
- data/spec/rails3.1/config/environments/test.rb +34 -0
- data/spec/rails3.1/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails3.1/config/initializers/inflections.rb +10 -0
- data/spec/rails3.1/config/initializers/mime_types.rb +5 -0
- data/spec/rails3.1/config/initializers/secret_token.rb +7 -0
- data/spec/rails3.1/config/initializers/session_store.rb +8 -0
- data/spec/rails3.1/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails3.1/config/routes.rb +7 -0
- data/spec/rails3.1/log/.gitkeep +0 -0
- data/spec/rails_form_spec.rb +63 -0
- data/spec/spec_helper.rb +27 -0
- data/tmp/cache/assets/C93/520/sprockets%2Fc677444919ef374b958536e6f24b15b1 +0 -0
- data/tmp/cache/assets/CA5/380/sprockets%2F1ff55d945a664b750021ba61a96c0274 +0 -0
- data/tmp/cache/assets/CB2/300/sprockets%2Fc3870b357b9ca1b89950483165c0d8e0 +0 -0
- data/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/tmp/cache/assets/CDE/4B0/sprockets%2Fc589c30dd77520ba7fd4e16466a32192 +0 -0
- data/tmp/cache/assets/CEE/5F0/sprockets%2F54d38a9c813681d2838b96ebe140e84f +0 -0
- data/tmp/cache/assets/D19/8A0/sprockets%2F8870aaaed853f1b2d489b199327f802e +0 -0
- data/tmp/cache/assets/D24/3C0/sprockets%2F4b5f582b8f52d50f96d396837b44ace8 +0 -0
- data/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/tmp/cache/assets/D4F/C40/sprockets%2F6eef3882347ce72578caca5865b80cb6 +0 -0
- data/tmp/cache/assets/D50/850/sprockets%2F4acc8287556eb57079e6978b4a11bedf +0 -0
- data/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/tmp/cache/assets/D6F/BC0/sprockets%2Fcf7528da181e32b8e758e3d603cbba29 +0 -0
- data/tmp/cache/assets/D91/080/sprockets%2F3cc81f1bd8d23d9c1aab48c520e450f6 +0 -0
- data/tmp/cache/assets/DA6/150/sprockets%2F1eeb0387fb8841ef86accfe15932c72c +0 -0
- data/tmp/cache/assets/DAA/7E0/sprockets%2F423e3888dde6a807610fcaeb6de68c5e +0 -0
- data/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/tmp/cache/assets/E26/AB0/sprockets%2Fc9abd9afeb3c158ad7aba136830f5cc6 +0 -0
- data/tmp/cache/assets/E2F/490/sprockets%2Fbee5b646eaa5f1f0ce53f413cf9bc59d +0 -0
- data/tmp/cache/assets/E66/560/sprockets%2Fd5e10c4f3e90a44eb2dffccfefe8594e +0 -0
- data/webrat.log +201 -0
- metadata +139 -8
data/README.md
CHANGED
@@ -1,10 +1,27 @@
|
|
1
1
|
Unobtrusive Javascript Form Extensions for Rails 3
|
2
2
|
==================================================
|
3
3
|
|
4
|
-
|
4
|
+
Edifice-widgets is a companion gem to [edifice](/tmeasday/edifice) which improves and simplifies your experience writing forms for rails.
|
5
5
|
|
6
6
|
Note that it does not depend on edifice, although it complements it well.
|
7
7
|
|
8
|
+
Installation
|
9
|
+
------------
|
10
|
+
|
11
|
+
To install, simply add to your Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'edifice-forms'
|
15
|
+
```
|
16
|
+
|
17
|
+
To include the javascript, add to your application.js:
|
18
|
+
|
19
|
+
```js
|
20
|
+
/*
|
21
|
+
*= require edifice-forms
|
22
|
+
*/
|
23
|
+
```
|
24
|
+
|
8
25
|
Extending remote forms to handle errors
|
9
26
|
---------------------------------------
|
10
27
|
|
@@ -105,9 +122,11 @@ class Feedback < Edifice::Forms::FormModel
|
|
105
122
|
validates :email, :presence => true, :format => {:with => /^.+@.+\..+$/}
|
106
123
|
validates :message, :presence => true
|
107
124
|
|
125
|
+
after_save :deliver_feedback
|
126
|
+
|
108
127
|
# if validations pass and we successfully save, go ahead and deliver the
|
109
128
|
# feedback email to us, so we can read it.
|
110
|
-
def
|
129
|
+
def deliver_feedback
|
111
130
|
SelfMailer.feedback(self).deliver
|
112
131
|
end
|
113
132
|
end
|
@@ -143,4 +162,4 @@ Simple, huh?
|
|
143
162
|
License
|
144
163
|
-------
|
145
164
|
|
146
|
-
Edifice is crafted by [Percolate Studio](http://percolatestudio.com) and released under the [MIT license](www.opensource.org/licenses/MIT)
|
165
|
+
[Edifice](http://edifice-rails.com) is crafted by [Percolate Studio](http://percolatestudio.com) and released under the [MIT license](www.opensource.org/licenses/MIT)
|
data/Rakefile
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
// jquery.escape 1.0 - escape strings for use in jQuery selectors
|
2
|
+
// http://ianloic.com/tag/jquery.escape
|
3
|
+
// Copyright 2009 Ian McKellar <http://ian.mckellar.org/>
|
4
|
+
// Just like jQuery you can use it under either the MIT license or the GPL
|
5
|
+
// (see: http://docs.jquery.com/License)
|
6
|
+
(function() {
|
7
|
+
escape_re = /[#;&,\.\+\*~':"!\^\$\[\]\(\)=>|\/\\]/;
|
8
|
+
jQuery.escape = function jQuery$escape(s) {
|
9
|
+
var left = s.split(escape_re, 1)[0];
|
10
|
+
if (left == s) return s;
|
11
|
+
return left + '\\' +
|
12
|
+
s.substr(left.length, 1) +
|
13
|
+
jQuery.escape(s.substr(left.length+1));
|
14
|
+
}
|
15
|
+
})();
|
@@ -16,7 +16,7 @@ $.fn.rails_form = function(method) {
|
|
16
16
|
// in these 'this' is the $form
|
17
17
|
var methods = {
|
18
18
|
fields: function() {
|
19
|
-
return this.find('input, textarea, select');
|
19
|
+
return this.find('input:not([type=hidden]):not([type=submit]), textarea, select');
|
20
20
|
},
|
21
21
|
|
22
22
|
field: function(name_or_field) {
|
@@ -14,7 +14,15 @@
|
|
14
14
|
|
15
15
|
} else if (/json/.test(contentType)) {
|
16
16
|
// we will be receiving an error object back, we can pass it straight into rails_form.js
|
17
|
-
$(
|
17
|
+
$('body').append('<pre>' + request.responseText + '</pre>');
|
18
|
+
var errors = $.parseJSON(request.responseText);
|
19
|
+
|
20
|
+
// they are using namespaced JSON
|
21
|
+
if ('errors' in errors && !$.isArray(errors['errors'])) {
|
22
|
+
errors = errors['errors']
|
23
|
+
}
|
24
|
+
|
25
|
+
$(this).rails_form('set_errors', errors);
|
18
26
|
} else {
|
19
27
|
throw "edifice-forms/show-errors: Don't know how to handle dataType " + request.dataType;
|
20
28
|
}
|
data/edifice-forms.gemspec
CHANGED
@@ -7,7 +7,8 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.author = 'Tom Coleman'
|
9
9
|
s.email = 'tom@percolatestudio.com'
|
10
|
-
s.summary = 'Unobtrusive JS Form extensions'
|
10
|
+
s.summary = 'Unobtrusive Rails JS Form extensions'
|
11
|
+
s.description = 'Edifice-widgets is a companion gem to edifice which improves and simplifies your experience writing forms for rails.'
|
11
12
|
|
12
13
|
s.add_dependency 'jquery-rails'
|
13
14
|
|
@@ -15,4 +16,9 @@ Gem::Specification.new do |s|
|
|
15
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
18
|
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_development_dependency 'rake'
|
21
|
+
s.add_development_dependency 'rails'
|
22
|
+
s.add_development_dependency 'rspec-rails'
|
23
|
+
s.add_development_dependency 'capybara'
|
18
24
|
end
|
@@ -4,14 +4,15 @@ module Edifice
|
|
4
4
|
class Responder < ActionController::Responder
|
5
5
|
protected
|
6
6
|
# add the :u_e header to xhr error requests
|
7
|
-
def
|
7
|
+
def navigation_behavior(error)
|
8
|
+
::Rails.logger.warn '>>>>>>> has_errors? is: ' + (has_errors? ? 'true' : 'false')
|
8
9
|
if controller.request.xhr? && !get? and has_errors? && default_action
|
9
10
|
render :action => default_action, :status => :unprocessable_entity, :layout => nil
|
10
11
|
else
|
11
|
-
super
|
12
|
+
super(error)
|
12
13
|
end
|
13
14
|
end
|
14
|
-
|
15
|
+
|
15
16
|
# actually render something on successful updates
|
16
17
|
def to_format
|
17
18
|
unless get? or has_errors? or post?
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for :form_that_shows_errors do
|
4
|
+
it "should show errors when validation fails" do
|
5
|
+
page.click_button('Submit')
|
6
|
+
|
7
|
+
page.should have_error_on 'user_name'
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should show errors when validation fails in .errors" do
|
11
|
+
page.click_button('Submit')
|
12
|
+
|
13
|
+
page.should have_rendered_error_on 'user_name'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "not change when validation succeeds" do
|
17
|
+
page.fill_in 'Name', :with => 'whatever'
|
18
|
+
page.click_button('Submit')
|
19
|
+
|
20
|
+
page.should have_no_error_on 'user_name'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'html forms with show_errors', :type => :request, :js => true do
|
25
|
+
before(:each) do
|
26
|
+
page.visit('/users/new?type=html&ajax=false')
|
27
|
+
end
|
28
|
+
|
29
|
+
it_behaves_like :form_that_shows_errors
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'json forms with show_errors', :type => :request, :js => true do
|
33
|
+
before(:each) do
|
34
|
+
page.visit('/users/new?type=json&ajax=false')
|
35
|
+
end
|
36
|
+
|
37
|
+
it_behaves_like :form_that_shows_errors
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'ajax html forms with show_errors', :type => :request, :js => true do
|
41
|
+
before(:each) do
|
42
|
+
page.visit('/users/new?type=html&ajax=true')
|
43
|
+
end
|
44
|
+
|
45
|
+
it_behaves_like :form_that_shows_errors
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'ajax json forms with show_errors', :type => :request, :js => true do
|
49
|
+
before(:each) do
|
50
|
+
page.visit('/users/new?type=json&ajax=true')
|
51
|
+
end
|
52
|
+
|
53
|
+
it_behaves_like :form_that_shows_errors
|
54
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe UsersController do
|
4
|
+
include RSpec::Rails::ControllerExampleGroup
|
5
|
+
|
6
|
+
it 'should return new' do
|
7
|
+
get 'new'
|
8
|
+
|
9
|
+
response.should render_template(:new)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should behave correctly on validation errors' do
|
13
|
+
post 'create', :user => {:name => ''}
|
14
|
+
|
15
|
+
response.should render_template(:new)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should update successfully' do
|
19
|
+
User.should_receive(:model_saved)
|
20
|
+
|
21
|
+
post 'create', :user => {:name => 'a lengthy name'}
|
22
|
+
|
23
|
+
response.should redirect_to(users_path)
|
24
|
+
end
|
25
|
+
end
|
Binary file
|
@@ -0,0 +1,10 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
|
+
// the compiled file.
|
6
|
+
//
|
7
|
+
//= require jquery
|
8
|
+
//= require jquery_ujs
|
9
|
+
//= require edifice-forms
|
10
|
+
//= require_tree .
|
@@ -0,0 +1,264 @@
|
|
1
|
+
// jquery.pjax.js
|
2
|
+
// copyright chris wanstrath
|
3
|
+
// https://github.com/defunkt/jquery-pjax
|
4
|
+
|
5
|
+
(function($){
|
6
|
+
|
7
|
+
// When called on a link, fetches the href with ajax into the
|
8
|
+
// container specified as the first parameter or with the data-pjax
|
9
|
+
// attribute on the link itself.
|
10
|
+
//
|
11
|
+
// Tries to make sure the back button and ctrl+click work the way
|
12
|
+
// you'd expect.
|
13
|
+
//
|
14
|
+
// Accepts a jQuery ajax options object that may include these
|
15
|
+
// pjax specific options:
|
16
|
+
//
|
17
|
+
// container - Where to stick the response body. Usually a String selector.
|
18
|
+
// $(container).html(xhr.responseBody)
|
19
|
+
// push - Whether to pushState the URL. Defaults to true (of course).
|
20
|
+
// replace - Want to use replaceState instead? That's cool.
|
21
|
+
//
|
22
|
+
// For convenience the first parameter can be either the container or
|
23
|
+
// the options object.
|
24
|
+
//
|
25
|
+
// Returns the jQuery object
|
26
|
+
$.fn.pjax = function( container, options ) {
|
27
|
+
if ( options )
|
28
|
+
options.container = container
|
29
|
+
else
|
30
|
+
options = $.isPlainObject(container) ? container : {container:container}
|
31
|
+
|
32
|
+
// We can't persist $objects using the history API so we must use
|
33
|
+
// a String selector. Bail if we got anything else.
|
34
|
+
if ( options.container && typeof options.container !== 'string' ) {
|
35
|
+
throw "pjax container must be a string selector!"
|
36
|
+
return false
|
37
|
+
}
|
38
|
+
|
39
|
+
return this.live('click', function(event){
|
40
|
+
// Middle click, cmd click, and ctrl click should open
|
41
|
+
// links in a new tab as normal.
|
42
|
+
if ( event.which > 1 || event.metaKey )
|
43
|
+
return true
|
44
|
+
|
45
|
+
var defaults = {
|
46
|
+
url: this.href,
|
47
|
+
container: $(this).attr('data-pjax'),
|
48
|
+
clickedElement: $(this),
|
49
|
+
fragment: null
|
50
|
+
}
|
51
|
+
|
52
|
+
$.pjax($.extend({}, defaults, options))
|
53
|
+
|
54
|
+
event.preventDefault()
|
55
|
+
})
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
// Loads a URL with ajax, puts the response body inside a container,
|
60
|
+
// then pushState()'s the loaded URL.
|
61
|
+
//
|
62
|
+
// Works just like $.ajax in that it accepts a jQuery ajax
|
63
|
+
// settings object (with keys like url, type, data, etc).
|
64
|
+
//
|
65
|
+
// Accepts these extra keys:
|
66
|
+
//
|
67
|
+
// container - Where to stick the response body. Must be a String.
|
68
|
+
// $(container).html(xhr.responseBody)
|
69
|
+
// push - Whether to pushState the URL. Defaults to true (of course).
|
70
|
+
// replace - Want to use replaceState instead? That's cool.
|
71
|
+
//
|
72
|
+
// Use it just like $.ajax:
|
73
|
+
//
|
74
|
+
// var xhr = $.pjax({ url: this.href, container: '#main' })
|
75
|
+
// console.log( xhr.readyState )
|
76
|
+
//
|
77
|
+
// Returns whatever $.ajax returns.
|
78
|
+
var pjax = $.pjax = function( options ) {
|
79
|
+
var $container = $(options.container),
|
80
|
+
success = options.success || $.noop
|
81
|
+
|
82
|
+
// We don't want to let anyone override our success handler.
|
83
|
+
delete options.success
|
84
|
+
|
85
|
+
// We can't persist $objects using the history API so we must use
|
86
|
+
// a String selector. Bail if we got anything else.
|
87
|
+
if ( typeof options.container !== 'string' )
|
88
|
+
throw "pjax container must be a string selector!"
|
89
|
+
|
90
|
+
options = $.extend(true, {}, pjax.defaults, options)
|
91
|
+
|
92
|
+
if ( $.isFunction(options.url) ) {
|
93
|
+
options.url = options.url()
|
94
|
+
}
|
95
|
+
|
96
|
+
options.context = $container
|
97
|
+
|
98
|
+
options.success = function(data){
|
99
|
+
if ( options.fragment ) {
|
100
|
+
// If they specified a fragment, look for it in the response
|
101
|
+
// and pull it out.
|
102
|
+
var $fragment = $(data).find(options.fragment)
|
103
|
+
if ( $fragment.length )
|
104
|
+
data = $fragment.children()
|
105
|
+
else
|
106
|
+
return window.location = options.url
|
107
|
+
} else {
|
108
|
+
// If we got no data or an entire web page, go directly
|
109
|
+
// to the page and let normal error handling happen.
|
110
|
+
if ( !$.trim(data) || /<html/i.test(data) )
|
111
|
+
return window.location = options.url
|
112
|
+
}
|
113
|
+
|
114
|
+
// Make it happen.
|
115
|
+
this.html(data)
|
116
|
+
|
117
|
+
// If there's a <title> tag in the response, use it as
|
118
|
+
// the page's title.
|
119
|
+
var oldTitle = document.title,
|
120
|
+
title = $.trim( this.find('title').remove().text() )
|
121
|
+
if ( title ) document.title = title
|
122
|
+
|
123
|
+
// No <title>? Fragment? Look for data-title and title attributes.
|
124
|
+
if ( !title && options.fragment ) {
|
125
|
+
title = $fragment.attr('title') || $fragment.data('title')
|
126
|
+
}
|
127
|
+
|
128
|
+
var state = {
|
129
|
+
pjax: options.container,
|
130
|
+
fragment: options.fragment,
|
131
|
+
timeout: options.timeout
|
132
|
+
}
|
133
|
+
|
134
|
+
// If there are extra params, save the complete URL in the state object
|
135
|
+
var query = $.param(options.data)
|
136
|
+
if ( query != "_pjax=true" )
|
137
|
+
state.url = options.url + (/\?/.test(options.url) ? "&" : "?") + query
|
138
|
+
|
139
|
+
if ( options.replace ) {
|
140
|
+
window.history.replaceState(state, document.title, options.url)
|
141
|
+
} else if ( options.push ) {
|
142
|
+
// this extra replaceState before first push ensures good back
|
143
|
+
// button behavior
|
144
|
+
if ( !pjax.active ) {
|
145
|
+
window.history.replaceState($.extend({}, state, {url:null}), oldTitle)
|
146
|
+
pjax.active = true
|
147
|
+
}
|
148
|
+
|
149
|
+
window.history.pushState(state, document.title, options.url)
|
150
|
+
}
|
151
|
+
|
152
|
+
// Google Analytics support
|
153
|
+
if ( (options.replace || options.push) && window._gaq )
|
154
|
+
_gaq.push(['_trackPageview'])
|
155
|
+
|
156
|
+
// If the URL has a hash in it, make sure the browser
|
157
|
+
// knows to navigate to the hash.
|
158
|
+
var hash = window.location.hash.toString()
|
159
|
+
if ( hash !== '' ) {
|
160
|
+
window.location.href = hash
|
161
|
+
}
|
162
|
+
|
163
|
+
// Invoke their success handler if they gave us one.
|
164
|
+
success.apply(this, arguments)
|
165
|
+
}
|
166
|
+
|
167
|
+
// Cancel the current request if we're already pjaxing
|
168
|
+
var xhr = pjax.xhr
|
169
|
+
if ( xhr && xhr.readyState < 4) {
|
170
|
+
xhr.onreadystatechange = $.noop
|
171
|
+
xhr.abort()
|
172
|
+
}
|
173
|
+
|
174
|
+
pjax.options = options
|
175
|
+
pjax.xhr = $.ajax(options)
|
176
|
+
$(document).trigger('pjax', [pjax.xhr, options])
|
177
|
+
|
178
|
+
return pjax.xhr
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
pjax.defaults = {
|
183
|
+
timeout: 650,
|
184
|
+
push: true,
|
185
|
+
replace: false,
|
186
|
+
// We want the browser to maintain two separate internal caches: one for
|
187
|
+
// pjax'd partial page loads and one for normal page loads. Without
|
188
|
+
// adding this secret parameter, some browsers will often confuse the two.
|
189
|
+
data: { _pjax: true },
|
190
|
+
type: 'GET',
|
191
|
+
dataType: 'html',
|
192
|
+
beforeSend: function(xhr){
|
193
|
+
this.trigger('pjax:start', [xhr, pjax.options])
|
194
|
+
// start.pjax is deprecated
|
195
|
+
this.trigger('start.pjax', [xhr, pjax.options])
|
196
|
+
xhr.setRequestHeader('X-PJAX', 'true')
|
197
|
+
},
|
198
|
+
error: function(xhr, textStatus, errorThrown){
|
199
|
+
if ( textStatus !== 'abort' )
|
200
|
+
window.location = pjax.options.url
|
201
|
+
},
|
202
|
+
complete: function(xhr){
|
203
|
+
this.trigger('pjax:end', [xhr, pjax.options])
|
204
|
+
// end.pjax is deprecated
|
205
|
+
this.trigger('end.pjax', [xhr, pjax.options])
|
206
|
+
}
|
207
|
+
}
|
208
|
+
|
209
|
+
|
210
|
+
// Used to detect initial (useless) popstate.
|
211
|
+
// If history.state exists, assume browser isn't going to fire initial popstate.
|
212
|
+
var popped = ('state' in window.history), initialURL = location.href
|
213
|
+
|
214
|
+
|
215
|
+
// popstate handler takes care of the back and forward buttons
|
216
|
+
//
|
217
|
+
// You probably shouldn't use pjax on pages with other pushState
|
218
|
+
// stuff yet.
|
219
|
+
$(window).bind('popstate', function(event){
|
220
|
+
// Ignore inital popstate that some browsers fire on page load
|
221
|
+
var initialPop = !popped && location.href == initialURL
|
222
|
+
popped = true
|
223
|
+
if ( initialPop ) return
|
224
|
+
|
225
|
+
var state = event.state
|
226
|
+
|
227
|
+
if ( state && state.pjax ) {
|
228
|
+
var container = state.pjax
|
229
|
+
if ( $(container+'').length )
|
230
|
+
$.pjax({
|
231
|
+
url: state.url || location.href,
|
232
|
+
fragment: state.fragment,
|
233
|
+
container: container,
|
234
|
+
push: false,
|
235
|
+
timeout: state.timeout
|
236
|
+
})
|
237
|
+
else
|
238
|
+
window.location = location.href
|
239
|
+
}
|
240
|
+
})
|
241
|
+
|
242
|
+
|
243
|
+
// Add the state property to jQuery's event object so we can use it in
|
244
|
+
// $(window).bind('popstate')
|
245
|
+
if ( $.inArray('state', $.event.props) < 0 )
|
246
|
+
$.event.props.push('state')
|
247
|
+
|
248
|
+
|
249
|
+
// Is pjax supported by this browser?
|
250
|
+
$.support.pjax =
|
251
|
+
window.history && window.history.pushState && window.history.replaceState
|
252
|
+
// pushState isn't reliable on iOS yet.
|
253
|
+
&& !navigator.userAgent.match(/(iPod|iPhone|iPad|WebApps\/.+CFNetwork)/)
|
254
|
+
|
255
|
+
|
256
|
+
// Fall back to normalcy for older browsers.
|
257
|
+
if ( !$.support.pjax ) {
|
258
|
+
$.pjax = function( options ) {
|
259
|
+
window.location = $.isFunction(options.url) ? options.url() : options.url
|
260
|
+
}
|
261
|
+
$.fn.pjax = function() { return this }
|
262
|
+
}
|
263
|
+
|
264
|
+
})(jQuery);
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
5
|
+
*= require_self
|
6
|
+
*= require_tree .
|
7
|
+
*/
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class UsersController < ApplicationController
|
2
|
+
respond_to :html, :json
|
3
|
+
|
4
|
+
def new
|
5
|
+
@type = params[:type] || 'html'
|
6
|
+
@ajax = params[:ajax] || false
|
7
|
+
|
8
|
+
respond_with @user = User.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def create
|
12
|
+
respond_with @user = User.create(params[:user])
|
13
|
+
end
|
14
|
+
|
15
|
+
def index
|
16
|
+
head :ok
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class User < Edifice::Forms::FormModel
|
2
|
+
attr_accessor :name, :location, :description
|
3
|
+
|
4
|
+
validates :name, :length => {:minimum => 3}, :presence => true
|
5
|
+
|
6
|
+
after_save :log_save
|
7
|
+
|
8
|
+
def log_save
|
9
|
+
User.model_saved
|
10
|
+
end
|
11
|
+
|
12
|
+
# this is just here so we can easily test for it.
|
13
|
+
def self.model_saved
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%= form_for @user, :remote => @ajax,
|
2
|
+
:html => {:'data-form' => 'show_errors', :'data-type' => @type} do |f| %>
|
3
|
+
<%= render_errors(f) %>
|
4
|
+
|
5
|
+
<%= f.label :name %>
|
6
|
+
<%= f.text_field :name %>
|
7
|
+
|
8
|
+
<%= f.label :location %>
|
9
|
+
<%= f.text_field :location %>
|
10
|
+
|
11
|
+
<%= f.label :description %>
|
12
|
+
<%= f.text_field :description %>
|
13
|
+
|
14
|
+
<button type="submit">Submit</button>
|
15
|
+
<% end %>
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require "action_controller/railtie"
|
4
|
+
require "sprockets/railtie"
|
5
|
+
|
6
|
+
require 'jquery-rails'
|
7
|
+
require 'edifice-forms'
|
8
|
+
|
9
|
+
if defined?(Bundler)
|
10
|
+
# If you precompile assets before deploying to production, use this line
|
11
|
+
Bundler.require(*Rails.groups(:assets => %w(development test)))
|
12
|
+
# If you want your assets lazily compiled in production, use this line
|
13
|
+
# Bundler.require(:default, :assets, Rails.env)
|
14
|
+
end
|
15
|
+
|
16
|
+
module Rails31
|
17
|
+
class Application < Rails::Application
|
18
|
+
# don't know how i was supposed to set this
|
19
|
+
config.root = ENV['RAILS_ROOT']
|
20
|
+
|
21
|
+
# Settings in config/environments/* take precedence over those specified here.
|
22
|
+
# Application configuration should go into files in config/initializers
|
23
|
+
# -- all .rb files in that directory are automatically loaded.
|
24
|
+
|
25
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
26
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
27
|
+
|
28
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
29
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
30
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
31
|
+
|
32
|
+
# Activate observers that should always be running.
|
33
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
34
|
+
|
35
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
36
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
37
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
38
|
+
|
39
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
40
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
41
|
+
# config.i18n.default_locale = :de
|
42
|
+
|
43
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
44
|
+
config.encoding = "utf-8"
|
45
|
+
|
46
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
47
|
+
config.filter_parameters += [:password]
|
48
|
+
|
49
|
+
# Enable the asset pipeline
|
50
|
+
config.assets.enabled = true
|
51
|
+
|
52
|
+
# Version of your assets, change this if you want to expire all your assets
|
53
|
+
config.assets.version = '1.0'
|
54
|
+
end
|
55
|
+
end
|