slug-engine 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ module SlugHelper
2
+
3
+ def slug_path(content)
4
+ if content.respond_to?(:slug)
5
+ slug_engine.permalink_path(content.slug)
6
+ else
7
+ polymorphic_path(content)
8
+ end
9
+ end
10
+
11
+ def slug_url(content)
12
+ if content.respond_to?(:slug)
13
+ slug_engine.permalink_url(content.slug)
14
+ else
15
+ polymorphic_url(content)
16
+ end
17
+ end
18
+
19
+ end
@@ -7,6 +7,10 @@ class Permalink < ActiveRecord::Base
7
7
  validates_uniqueness_of :slug
8
8
  validate :not_system_slug
9
9
 
10
+ def to_param
11
+ slug
12
+ end
13
+
10
14
  private
11
15
 
12
16
  # Validates that the slug is not routable to a controller other than PermalinksController
data/config/routes.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  Slug::Engine.routes.draw do
2
2
 
3
- get '*slug' => 'permalinks#show', :as => :slug
3
+ get '*slug' => 'permalinks#show', :as => :permalink
4
4
 
5
5
  end
data/lib/slug/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Slug
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -14,7 +14,7 @@
14
14
 
15
15
  <p>
16
16
  <b>Slug:</b>
17
- <%= link_to post.slug, slug_engine.slug_path(post.slug) %>
17
+ <%= link_to post.slug, slug_url(post) %>
18
18
  </p>
19
19
 
20
20
 
@@ -4473,3 +4473,296 @@ Served asset /users.js - 304 Not Modified (0ms)
4473
4473
 
4474
4474
  Started GET "/assets/application.js?body=1" for 127.0.0.1 at Sun Nov 13 17:30:16 -0500 2011
4475
4475
  Served asset /application.js - 304 Not Modified (0ms)
4476
+
4477
+
4478
+ Started GET "/" for 127.0.0.1 at Sun Nov 13 18:48:44 -0500 2011
4479
+ Processing by PostsController#index as HTML
4480
+ Post Load (0.2ms) SELECT "posts".* FROM "posts" 
4481
+ Permalink Load (0.1ms) SELECT "permalinks".* FROM "permalinks" WHERE "permalinks"."content_id" = 1 AND "permalinks"."content_type" = 'Post' LIMIT 1
4482
+ Rendered posts/index.html.erb within layouts/application (26.3ms)
4483
+ Cache for Asset (application.js) is stale
4484
+ /Users/jcarlson/.rvm/gems/ruby-1.8.7-p72@slug_engine/gems/jquery-rails-1.0.16/vendor/assets/javascripts/jquery.js isn't in paths: /Users/jcarlson/Projects/slug-engine/test/dummy/app/assets/images, /Users/jcarlson/Projects/slug-engine/test/dummy/app/assets/javascripts, /Users/jcarlson/Projects/slug-engine/test/dummy/app/assets/stylesheets, /Users/jcarlson/.rvm/gems/ruby-1.8.7-p72@slug-engine/gems/jquery-rails-1.0.16/vendor/assets/javascripts
4485
+ Compiled application.js (6ms) (pid 34485)
4486
+ Compiled jquery.js (4ms) (pid 34485)
4487
+ Compiled jquery_ujs.js (1ms) (pid 34485)
4488
+ Completed 200 OK in 140ms (Views: 138.1ms | ActiveRecord: 0.7ms)
4489
+
4490
+
4491
+ Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at Sun Nov 13 18:48:45 -0500 2011
4492
+ Served asset /jquery_ujs.js - 200 OK (2ms)
4493
+
4494
+
4495
+ Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at Sun Nov 13 18:48:45 -0500 2011
4496
+ Served asset /jquery.js - 200 OK (11ms)
4497
+
4498
+
4499
+ Started GET "/assets/users.css?body=1" for 127.0.0.1 at Sun Nov 13 18:48:45 -0500 2011
4500
+ Served asset /users.css - 304 Not Modified (5ms)
4501
+
4502
+
4503
+ Started GET "/assets/scaffold.css?body=1" for 127.0.0.1 at Sun Nov 13 18:48:45 -0500 2011
4504
+ Served asset /scaffold.css - 304 Not Modified (3ms)
4505
+
4506
+
4507
+ Started GET "/assets/posts.css?body=1" for 127.0.0.1 at Sun Nov 13 18:48:45 -0500 2011
4508
+ Served asset /posts.css - 304 Not Modified (2ms)
4509
+
4510
+
4511
+ Started GET "/assets/posts.js?body=1" for 127.0.0.1 at Sun Nov 13 18:48:45 -0500 2011
4512
+ Served asset /posts.js - 304 Not Modified (1ms)
4513
+
4514
+
4515
+ Started GET "/assets/users.js?body=1" for 127.0.0.1 at Sun Nov 13 18:48:45 -0500 2011
4516
+ Served asset /users.js - 304 Not Modified (1ms)
4517
+
4518
+
4519
+ Started GET "/posts/1" for 127.0.0.1 at Sun Nov 13 18:48:47 -0500 2011
4520
+ Processing by PostsController#show as HTML
4521
+ Parameters: {"id"=>"1"}
4522
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "1"]]
4523
+ Permalink Load (0.1ms) SELECT "permalinks".* FROM "permalinks" WHERE "permalinks"."content_id" = 1 AND "permalinks"."content_type" = 'Post' LIMIT 1
4524
+ Rendered posts/_post.html.erb (63.7ms)
4525
+ Rendered posts/show.html.erb within layouts/application (70.2ms)
4526
+ Completed 200 OK in 82ms (Views: 79.8ms | ActiveRecord: 0.7ms)
4527
+
4528
+
4529
+ Started GET "/assets/users.js?body=1" for 127.0.0.1 at Sun Nov 13 18:48:47 -0500 2011
4530
+ Served asset /users.js - 304 Not Modified (0ms)
4531
+
4532
+
4533
+ Started GET "/assets/users.css?body=1" for 127.0.0.1 at Sun Nov 13 18:48:47 -0500 2011
4534
+ Served asset /users.css - 304 Not Modified (0ms)
4535
+
4536
+
4537
+ Started GET "/assets/scaffold.css?body=1" for 127.0.0.1 at Sun Nov 13 18:48:47 -0500 2011
4538
+ Served asset /scaffold.css - 304 Not Modified (0ms)
4539
+
4540
+
4541
+ Started GET "/assets/posts.css?body=1" for 127.0.0.1 at Sun Nov 13 18:48:47 -0500 2011
4542
+ Served asset /posts.css - 304 Not Modified (0ms)
4543
+
4544
+
4545
+ Started GET "/assets/posts.js?body=1" for 127.0.0.1 at Sun Nov 13 18:48:47 -0500 2011
4546
+ Served asset /posts.js - 304 Not Modified (0ms)
4547
+
4548
+
4549
+ Started GET "/posts/1" for 127.0.0.1 at Sun Nov 13 18:49:02 -0500 2011
4550
+ Processing by PostsController#show as HTML
4551
+ Parameters: {"id"=>"1"}
4552
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "1"]]
4553
+ Permalink Load (0.2ms) SELECT "permalinks".* FROM "permalinks" WHERE "permalinks"."content_id" = 1 AND "permalinks"."content_type" = 'Post' LIMIT 1
4554
+ Rendered posts/_post.html.erb (11.5ms)
4555
+ Rendered posts/show.html.erb within layouts/application (15.4ms)
4556
+ Completed 200 OK in 28ms (Views: 25.3ms | ActiveRecord: 0.8ms)
4557
+
4558
+
4559
+ Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at Sun Nov 13 18:49:02 -0500 2011
4560
+ Served asset /jquery.js - 304 Not Modified (0ms)
4561
+
4562
+
4563
+ Started GET "/assets/scaffold.css?body=1" for 127.0.0.1 at Sun Nov 13 18:49:02 -0500 2011
4564
+ Served asset /scaffold.css - 304 Not Modified (0ms)
4565
+
4566
+
4567
+ Started GET "/assets/posts.css?body=1" for 127.0.0.1 at Sun Nov 13 18:49:02 -0500 2011
4568
+ Served asset /posts.css - 304 Not Modified (0ms)
4569
+
4570
+
4571
+ Started GET "/assets/application.css?body=1" for 127.0.0.1 at Sun Nov 13 18:49:02 -0500 2011
4572
+ Served asset /application.css - 200 OK (3ms)
4573
+
4574
+
4575
+ Started GET "/assets/users.css?body=1" for 127.0.0.1 at Sun Nov 13 18:49:02 -0500 2011
4576
+ Served asset /users.css - 304 Not Modified (0ms)
4577
+
4578
+
4579
+ Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at Sun Nov 13 18:49:02 -0500 2011
4580
+ Served asset /jquery_ujs.js - 304 Not Modified (0ms)
4581
+
4582
+
4583
+ Started GET "/assets/posts.js?body=1" for 127.0.0.1 at Sun Nov 13 18:49:02 -0500 2011
4584
+ Served asset /posts.js - 304 Not Modified (0ms)
4585
+
4586
+
4587
+ Started GET "/assets/users.js?body=1" for 127.0.0.1 at Sun Nov 13 18:49:02 -0500 2011
4588
+ Served asset /users.js - 304 Not Modified (0ms)
4589
+
4590
+
4591
+ Started GET "/assets/application.js?body=1" for 127.0.0.1 at Sun Nov 13 18:49:02 -0500 2011
4592
+ Served asset /application.js - 200 OK (0ms)
4593
+
4594
+
4595
+ Started GET "/posts/1" for 127.0.0.1 at Sun Nov 13 19:01:31 -0500 2011
4596
+ Processing by PostsController#show as HTML
4597
+ Parameters: {"id"=>"1"}
4598
+ Post Load (0.3ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "1"]]
4599
+ Permalink Load (0.5ms) SELECT "permalinks".* FROM "permalinks" WHERE "permalinks"."content_id" = 1 AND "permalinks"."content_type" = 'Post' LIMIT 1
4600
+ Rendered posts/_post.html.erb (22.6ms)
4601
+ Rendered posts/show.html.erb within layouts/application (30.9ms)
4602
+ Completed 200 OK in 115ms (Views: 62.0ms | ActiveRecord: 1.2ms)
4603
+
4604
+
4605
+ Started GET "/assets/users.css?body=1" for 127.0.0.1 at Sun Nov 13 19:01:32 -0500 2011
4606
+ Served asset /users.css - 304 Not Modified (2ms)
4607
+
4608
+
4609
+ Started GET "/assets/scaffold.css?body=1" for 127.0.0.1 at Sun Nov 13 19:01:32 -0500 2011
4610
+ Served asset /scaffold.css - 304 Not Modified (2ms)
4611
+
4612
+
4613
+ Started GET "/assets/posts.css?body=1" for 127.0.0.1 at Sun Nov 13 19:01:32 -0500 2011
4614
+ Served asset /posts.css - 304 Not Modified (3ms)
4615
+
4616
+
4617
+ Started GET "/assets/application.css?body=1" for 127.0.0.1 at Sun Nov 13 19:01:32 -0500 2011
4618
+ Served asset /application.css - 304 Not Modified (3ms)
4619
+
4620
+
4621
+ Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at Sun Nov 13 19:01:32 -0500 2011
4622
+ Served asset /jquery.js - 304 Not Modified (9ms)
4623
+
4624
+
4625
+ Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at Sun Nov 13 19:01:32 -0500 2011
4626
+ Served asset /jquery_ujs.js - 304 Not Modified (2ms)
4627
+
4628
+
4629
+ Started GET "/assets/posts.js?body=1" for 127.0.0.1 at Sun Nov 13 19:01:32 -0500 2011
4630
+ Served asset /posts.js - 304 Not Modified (74ms)
4631
+
4632
+
4633
+ Started GET "/assets/users.js?body=1" for 127.0.0.1 at Sun Nov 13 19:01:32 -0500 2011
4634
+ Served asset /users.js - 304 Not Modified (1ms)
4635
+
4636
+
4637
+ Started GET "/assets/application.js?body=1" for 127.0.0.1 at Sun Nov 13 19:01:32 -0500 2011
4638
+ Served asset /application.js - 304 Not Modified (0ms)
4639
+
4640
+
4641
+ Started GET "/posts/1" for 127.0.0.1 at Sun Nov 13 19:01:44 -0500 2011
4642
+ Processing by PostsController#show as HTML
4643
+ Parameters: {"id"=>"1"}
4644
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "1"]]
4645
+ Permalink Load (0.1ms) SELECT "permalinks".* FROM "permalinks" WHERE "permalinks"."content_id" = 1 AND "permalinks"."content_type" = 'Post' LIMIT 1
4646
+ Rendered posts/_post.html.erb (10.4ms)
4647
+ Rendered posts/show.html.erb within layouts/application (14.3ms)
4648
+ Completed 200 OK in 26ms (Views: 23.8ms | ActiveRecord: 0.7ms)
4649
+
4650
+
4651
+ Started GET "/posts/1" for 127.0.0.1 at Sun Nov 13 19:01:50 -0500 2011
4652
+ Processing by PostsController#show as HTML
4653
+ Parameters: {"id"=>"1"}
4654
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "1"]]
4655
+ Permalink Load (0.2ms) SELECT "permalinks".* FROM "permalinks" WHERE "permalinks"."content_id" = 1 AND "permalinks"."content_type" = 'Post' LIMIT 1
4656
+ Rendered posts/_post.html.erb (65.7ms)
4657
+ Rendered posts/show.html.erb within layouts/application (69.6ms)
4658
+ Completed 200 OK in 82ms (Views: 79.9ms | ActiveRecord: 0.8ms)
4659
+
4660
+
4661
+ Started GET "/posts/1" for 127.0.0.1 at Sun Nov 13 19:02:11 -0500 2011
4662
+ Processing by PostsController#show as HTML
4663
+ Parameters: {"id"=>"1"}
4664
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "1"]]
4665
+ Permalink Load (0.1ms) SELECT "permalinks".* FROM "permalinks" WHERE "permalinks"."content_id" = 1 AND "permalinks"."content_type" = 'Post' LIMIT 1
4666
+ Rendered posts/_post.html.erb (10.2ms)
4667
+ Rendered posts/show.html.erb within layouts/application (13.9ms)
4668
+ Completed 200 OK in 26ms (Views: 23.6ms | ActiveRecord: 0.7ms)
4669
+
4670
+
4671
+ Started GET "/posts/1" for 127.0.0.1 at Sun Nov 13 19:02:12 -0500 2011
4672
+ Processing by PostsController#show as HTML
4673
+ Parameters: {"id"=>"1"}
4674
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "1"]]
4675
+ Permalink Load (0.2ms) SELECT "permalinks".* FROM "permalinks" WHERE "permalinks"."content_id" = 1 AND "permalinks"."content_type" = 'Post' LIMIT 1
4676
+ Rendered posts/_post.html.erb (62.4ms)
4677
+ Rendered posts/show.html.erb within layouts/application (66.4ms)
4678
+ Completed 200 OK in 78ms (Views: 76.0ms | ActiveRecord: 0.8ms)
4679
+
4680
+
4681
+ Started GET "/posts/1" for 127.0.0.1 at Sun Nov 13 19:02:19 -0500 2011
4682
+ Processing by PostsController#show as HTML
4683
+ Parameters: {"id"=>"1"}
4684
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "1"]]
4685
+ Permalink Load (0.2ms) SELECT "permalinks".* FROM "permalinks" WHERE "permalinks"."content_id" = 1 AND "permalinks"."content_type" = 'Post' LIMIT 1
4686
+ Rendered posts/_post.html.erb (10.6ms)
4687
+ Rendered posts/show.html.erb within layouts/application (16.4ms)
4688
+ Completed 200 OK in 29ms (Views: 26.1ms | ActiveRecord: 0.8ms)
4689
+
4690
+
4691
+ Started GET "/posts/1" for 127.0.0.1 at Sun Nov 13 19:03:08 -0500 2011
4692
+ Processing by PostsController#show as HTML
4693
+ Parameters: {"id"=>"1"}
4694
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "1"]]
4695
+ Permalink Load (0.2ms) SELECT "permalinks".* FROM "permalinks" WHERE "permalinks"."content_id" = 1 AND "permalinks"."content_type" = 'Post' LIMIT 1
4696
+ Rendered posts/_post.html.erb (63.6ms)
4697
+ Rendered posts/show.html.erb within layouts/application (67.4ms)
4698
+ Completed 200 OK in 79ms (Views: 77.2ms | ActiveRecord: 0.7ms)
4699
+
4700
+
4701
+ Started GET "/posts/1" for 127.0.0.1 at Sun Nov 13 19:03:16 -0500 2011
4702
+ Processing by PostsController#show as HTML
4703
+ Parameters: {"id"=>"1"}
4704
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "1"]]
4705
+ Permalink Load (0.1ms) SELECT "permalinks".* FROM "permalinks" WHERE "permalinks"."content_id" = 1 AND "permalinks"."content_type" = 'Post' LIMIT 1
4706
+ Rendered posts/_post.html.erb (10.3ms)
4707
+ Rendered posts/show.html.erb within layouts/application (14.2ms)
4708
+ Completed 200 OK in 26ms (Views: 23.6ms | ActiveRecord: 0.7ms)
4709
+
4710
+
4711
+ Started GET "/posts/1" for 127.0.0.1 at Sun Nov 13 19:03:30 -0500 2011
4712
+ Processing by PostsController#show as HTML
4713
+ Parameters: {"id"=>"1"}
4714
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "1"]]
4715
+ Permalink Load (0.2ms) SELECT "permalinks".* FROM "permalinks" WHERE "permalinks"."content_id" = 1 AND "permalinks"."content_type" = 'Post' LIMIT 1
4716
+ Rendered posts/_post.html.erb (10.5ms)
4717
+ Rendered posts/show.html.erb within layouts/application (14.5ms)
4718
+ Completed 200 OK in 80ms (Views: 77.6ms | ActiveRecord: 0.7ms)
4719
+
4720
+
4721
+ Started GET "/posts/1" for 127.0.0.1 at Sun Nov 13 19:03:35 -0500 2011
4722
+ Processing by PostsController#show as HTML
4723
+ Parameters: {"id"=>"1"}
4724
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "1"]]
4725
+ Permalink Load (0.1ms) SELECT "permalinks".* FROM "permalinks" WHERE "permalinks"."content_id" = 1 AND "permalinks"."content_type" = 'Post' LIMIT 1
4726
+ Rendered posts/_post.html.erb (10.0ms)
4727
+ Rendered posts/show.html.erb within layouts/application (13.5ms)
4728
+ Completed 200 OK in 25ms (Views: 23.3ms | ActiveRecord: 0.7ms)
4729
+
4730
+
4731
+ Started GET "/posts/1" for 127.0.0.1 at Sun Nov 13 19:04:22 -0500 2011
4732
+ Processing by PostsController#show as HTML
4733
+ Parameters: {"id"=>"1"}
4734
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "1"]]
4735
+ Permalink Load (0.2ms) SELECT "permalinks".* FROM "permalinks" WHERE "permalinks"."content_id" = 1 AND "permalinks"."content_type" = 'Post' LIMIT 1
4736
+ Rendered posts/_post.html.erb (10.4ms)
4737
+ Rendered posts/show.html.erb within layouts/application (14.0ms)
4738
+ Completed 200 OK in 78ms (Views: 75.6ms | ActiveRecord: 0.7ms)
4739
+
4740
+
4741
+ Started GET "/posts/1" for 127.0.0.1 at Sun Nov 13 19:05:48 -0500 2011
4742
+ Processing by PostsController#show as HTML
4743
+ Parameters: {"id"=>"1"}
4744
+ Post Load (0.3ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "1"]]
4745
+ Permalink Load (0.1ms) SELECT "permalinks".* FROM "permalinks" WHERE "permalinks"."content_id" = 1 AND "permalinks"."content_type" = 'Post' LIMIT 1
4746
+ Rendered posts/_post.html.erb (24.1ms)
4747
+ Rendered posts/show.html.erb within layouts/application (32.7ms)
4748
+ Completed 200 OK in 119ms (Views: 63.8ms | ActiveRecord: 0.9ms)
4749
+
4750
+
4751
+ Started GET "/posts/1" for 127.0.0.1 at Sun Nov 13 19:06:10 -0500 2011
4752
+ Processing by PostsController#show as HTML
4753
+ Parameters: {"id"=>"1"}
4754
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "1"]]
4755
+ Permalink Load (0.2ms) SELECT "permalinks".* FROM "permalinks" WHERE "permalinks"."content_id" = 1 AND "permalinks"."content_type" = 'Post' LIMIT 1
4756
+ Rendered posts/_post.html.erb (10.7ms)
4757
+ Rendered posts/show.html.erb within layouts/application (14.4ms)
4758
+ Completed 200 OK in 28ms (Views: 25.4ms | ActiveRecord: 0.8ms)
4759
+
4760
+
4761
+ Started GET "/posts/1" for 127.0.0.1 at Sun Nov 13 19:06:16 -0500 2011
4762
+ Processing by PostsController#show as HTML
4763
+ Parameters: {"id"=>"1"}
4764
+ Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "1"]]
4765
+ Permalink Load (0.2ms) SELECT "permalinks".* FROM "permalinks" WHERE "permalinks"."content_id" = 1 AND "permalinks"."content_type" = 'Post' LIMIT 1
4766
+ Rendered posts/_post.html.erb (11.7ms)
4767
+ Rendered posts/show.html.erb within layouts/application (17.2ms)
4768
+ Completed 200 OK in 30ms (Views: 27.4ms | ActiveRecord: 0.8ms)
@@ -0,0 +1,372 @@
1
+ o: ActiveSupport::Cache::Entry :@compressedF: @value{"asset_paths["z/Users/jcarlson/.rvm/gems/ruby-1.8.7-p72@slug-engine/gems/jquery-rails-1.0.16/vendor/assets/javascripts/jquery_ujs.js" body";/**
2
+ * Unobtrusive scripting adapter for jQuery
3
+ *
4
+ * Requires jQuery 1.6.0 or later.
5
+ * https://github.com/rails/jquery-ujs
6
+
7
+ * Uploading file using rails.js
8
+ * =============================
9
+ *
10
+ * By default, browsers do not allow files to be uploaded via AJAX. As a result, if there are any non-blank file fields
11
+ * in the remote form, this adapter aborts the AJAX submission and allows the form to submit through standard means.
12
+ *
13
+ * The `ajax:aborted:file` event allows you to bind your own handler to process the form submission however you wish.
14
+ *
15
+ * Ex:
16
+ * $('form').live('ajax:aborted:file', function(event, elements){
17
+ * // Implement own remote file-transfer handler here for non-blank file inputs passed in `elements`.
18
+ * // Returning false in this handler tells rails.js to disallow standard form submission
19
+ * return false;
20
+ * });
21
+ *
22
+ * The `ajax:aborted:file` event is fired when a file-type input is detected with a non-blank value.
23
+ *
24
+ * Third-party tools can use this hook to detect when an AJAX file upload is attempted, and then use
25
+ * techniques like the iframe method to upload the file instead.
26
+ *
27
+ * Required fields in rails.js
28
+ * ===========================
29
+ *
30
+ * If any blank required inputs (required="required") are detected in the remote form, the whole form submission
31
+ * is canceled. Note that this is unlike file inputs, which still allow standard (non-AJAX) form submission.
32
+ *
33
+ * The `ajax:aborted:required` event allows you to bind your own handler to inform the user of blank required inputs.
34
+ *
35
+ * !! Note that Opera does not fire the form's submit event if there are blank required inputs, so this event may never
36
+ * get fired in Opera. This event is what causes other browsers to exhibit the same submit-aborting behavior.
37
+ *
38
+ * Ex:
39
+ * $('form').live('ajax:aborted:required', function(event, elements){
40
+ * // Returning false in this handler tells rails.js to submit the form anyway.
41
+ * // The blank required inputs are passed to this function in `elements`.
42
+ * return ! confirm("Would you like to submit the form with missing info?");
43
+ * });
44
+ */
45
+
46
+
47
+ (function($, undefined) {
48
+ // Shorthand to make it a little easier to call public rails functions from within rails.js
49
+ var rails;
50
+
51
+ $.rails = rails = {
52
+ // Link elements bound by jquery-ujs
53
+ linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]',
54
+
55
+ // Select elements bound by jquery-ujs
56
+ inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
57
+
58
+ // Form elements bound by jquery-ujs
59
+ formSubmitSelector: 'form',
60
+
61
+ // Form input elements bound by jquery-ujs
62
+ formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not(button[type])',
63
+
64
+ // Form input elements disabled during form submission
65
+ disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]',
66
+
67
+ // Form input elements re-enabled after form submission
68
+ enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled',
69
+
70
+ // Form required input elements
71
+ requiredInputSelector: 'input[name][required]:not([disabled]),textarea[name][required]:not([disabled])',
72
+
73
+ // Form file input elements
74
+ fileInputSelector: 'input:file',
75
+
76
+ // Link onClick disable selector with possible reenable after remote submission
77
+ linkDisableSelector: 'a[data-disable-with]',
78
+
79
+ // Make sure that every Ajax request sends the CSRF token
80
+ CSRFProtection: function(xhr) {
81
+ var token = $('meta[name="csrf-token"]').attr('content');
82
+ if (token) xhr.setRequestHeader('X-CSRF-Token', token);
83
+ },
84
+
85
+ // Triggers an event on an element and returns false if the event result is false
86
+ fire: function(obj, name, data) {
87
+ var event = $.Event(name);
88
+ obj.trigger(event, data);
89
+ return event.result !== false;
90
+ },
91
+
92
+ // Default confirm dialog, may be overridden with custom confirm dialog in $.rails.confirm
93
+ confirm: function(message) {
94
+ return confirm(message);
95
+ },
96
+
97
+ // Default ajax function, may be overridden with custom function in $.rails.ajax
98
+ ajax: function(options) {
99
+ return $.ajax(options);
100
+ },
101
+
102
+ // Submits "remote" forms and links with ajax
103
+ handleRemote: function(element) {
104
+ var method, url, data,
105
+ crossDomain = element.data('cross-domain') || null,
106
+ dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType),
107
+ options;
108
+
109
+ if (rails.fire(element, 'ajax:before')) {
110
+
111
+ if (element.is('form')) {
112
+ method = element.attr('method');
113
+ url = element.attr('action');
114
+ data = element.serializeArray();
115
+ // memoized value from clicked submit button
116
+ var button = element.data('ujs:submit-button');
117
+ if (button) {
118
+ data.push(button);
119
+ element.data('ujs:submit-button', null);
120
+ }
121
+ } else if (element.is(rails.inputChangeSelector)) {
122
+ method = element.data('method');
123
+ url = element.data('url');
124
+ data = element.serialize();
125
+ if (element.data('params')) data = data + "&" + element.data('params');
126
+ } else {
127
+ method = element.data('method');
128
+ url = element.attr('href');
129
+ data = element.data('params') || null;
130
+ }
131
+
132
+ options = {
133
+ type: method || 'GET', data: data, dataType: dataType, crossDomain: crossDomain,
134
+ // stopping the "ajax:beforeSend" event will cancel the ajax request
135
+ beforeSend: function(xhr, settings) {
136
+ if (settings.dataType === undefined) {
137
+ xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
138
+ }
139
+ return rails.fire(element, 'ajax:beforeSend', [xhr, settings]);
140
+ },
141
+ success: function(data, status, xhr) {
142
+ element.trigger('ajax:success', [data, status, xhr]);
143
+ },
144
+ complete: function(xhr, status) {
145
+ element.trigger('ajax:complete', [xhr, status]);
146
+ },
147
+ error: function(xhr, status, error) {
148
+ element.trigger('ajax:error', [xhr, status, error]);
149
+ }
150
+ };
151
+ // Only pass url to `ajax` options if not blank
152
+ if (url) { options.url = url; }
153
+
154
+ rails.ajax(options);
155
+ }
156
+ },
157
+
158
+ // Handles "data-method" on links such as:
159
+ // <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
160
+ handleMethod: function(link) {
161
+ var href = link.attr('href'),
162
+ method = link.data('method'),
163
+ target = link.attr('target'),
164
+ csrf_token = $('meta[name=csrf-token]').attr('content'),
165
+ csrf_param = $('meta[name=csrf-param]').attr('content'),
166
+ form = $('<form method="post" action="' + href + '"></form>'),
167
+ metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
168
+
169
+ if (csrf_param !== undefined && csrf_token !== undefined) {
170
+ metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
171
+ }
172
+
173
+ if (target) { form.attr('target', target); }
174
+
175
+ form.hide().append(metadata_input).appendTo('body');
176
+ form.submit();
177
+ },
178
+
179
+ /* Disables form elements:
180
+ - Caches element value in 'ujs:enable-with' data store
181
+ - Replaces element text with value of 'data-disable-with' attribute
182
+ - Sets disabled property to true
183
+ */
184
+ disableFormElements: function(form) {
185
+ form.find(rails.disableSelector).each(function() {
186
+ var element = $(this), method = element.is('button') ? 'html' : 'val';
187
+ element.data('ujs:enable-with', element[method]());
188
+ element[method](element.data('disable-with'));
189
+ element.prop('disabled', true);
190
+ });
191
+ },
192
+
193
+ /* Re-enables disabled form elements:
194
+ - Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`)
195
+ - Sets disabled property to false
196
+ */
197
+ enableFormElements: function(form) {
198
+ form.find(rails.enableSelector).each(function() {
199
+ var element = $(this), method = element.is('button') ? 'html' : 'val';
200
+ if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with'));
201
+ element.prop('disabled', false);
202
+ });
203
+ },
204
+
205
+ /* For 'data-confirm' attribute:
206
+ - Fires `confirm` event
207
+ - Shows the confirmation dialog
208
+ - Fires the `confirm:complete` event
209
+
210
+ Returns `true` if no function stops the chain and user chose yes; `false` otherwise.
211
+ Attaching a handler to the element's `confirm` event that returns a `falsy` value cancels the confirmation dialog.
212
+ Attaching a handler to the element's `confirm:complete` event that returns a `falsy` value makes this function
213
+ return false. The `confirm:complete` event is fired whether or not the user answered true or false to the dialog.
214
+ */
215
+ allowAction: function(element) {
216
+ var message = element.data('confirm'),
217
+ answer = false, callback;
218
+ if (!message) { return true; }
219
+
220
+ if (rails.fire(element, 'confirm')) {
221
+ answer = rails.confirm(message);
222
+ callback = rails.fire(element, 'confirm:complete', [answer]);
223
+ }
224
+ return answer && callback;
225
+ },
226
+
227
+ // Helper function which checks for blank inputs in a form that match the specified CSS selector
228
+ blankInputs: function(form, specifiedSelector, nonBlank) {
229
+ var inputs = $(), input,
230
+ selector = specifiedSelector || 'input,textarea';
231
+ form.find(selector).each(function() {
232
+ input = $(this);
233
+ // Collect non-blank inputs if nonBlank option is true, otherwise, collect blank inputs
234
+ if (nonBlank ? input.val() : !input.val()) {
235
+ inputs = inputs.add(input);
236
+ }
237
+ });
238
+ return inputs.length ? inputs : false;
239
+ },
240
+
241
+ // Helper function which checks for non-blank inputs in a form that match the specified CSS selector
242
+ nonBlankInputs: function(form, specifiedSelector) {
243
+ return rails.blankInputs(form, specifiedSelector, true); // true specifies nonBlank
244
+ },
245
+
246
+ // Helper function, needed to provide consistent behavior in IE
247
+ stopEverything: function(e) {
248
+ $(e.target).trigger('ujs:everythingStopped');
249
+ e.stopImmediatePropagation();
250
+ return false;
251
+ },
252
+
253
+ // find all the submit events directly bound to the form and
254
+ // manually invoke them. If anyone returns false then stop the loop
255
+ callFormSubmitBindings: function(form) {
256
+ var events = form.data('events'), continuePropagation = true;
257
+ if (events !== undefined && events['submit'] !== undefined) {
258
+ $.each(events['submit'], function(i, obj){
259
+ if (typeof obj.handler === 'function') return continuePropagation = obj.handler(obj.data);
260
+ });
261
+ }
262
+ return continuePropagation;
263
+ },
264
+
265
+ // replace element's html with the 'data-disable-with' after storing original html
266
+ // and prevent clicking on it
267
+ disableElement: function(element) {
268
+ element.data('ujs:enable-with', element.html()); // store enabled state
269
+ element.html(element.data('disable-with')); // set to disabled state
270
+ element.bind('click.railsDisable', function(e) { // prevent further clicking
271
+ return rails.stopEverything(e)
272
+ });
273
+ },
274
+
275
+ // restore element to its original state which was disabled by 'disableElement' above
276
+ enableElement: function(element) {
277
+ if (element.data('ujs:enable-with') !== undefined) {
278
+ element.html(element.data('ujs:enable-with')); // set to old enabled state
279
+ // this should be element.removeData('ujs:enable-with')
280
+ // but, there is currently a bug in jquery which makes hyphenated data attributes not get removed
281
+ element.data('ujs:enable-with', false); // clean up cache
282
+ }
283
+ element.unbind('click.railsDisable'); // enable element
284
+ }
285
+
286
+ };
287
+
288
+ $.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }});
289
+
290
+ $(rails.linkDisableSelector).live('ajax:complete', function() {
291
+ rails.enableElement($(this));
292
+ });
293
+
294
+ $(rails.linkClickSelector).live('click.rails', function(e) {
295
+ var link = $(this), method = link.data('method'), data = link.data('params');
296
+ if (!rails.allowAction(link)) return rails.stopEverything(e);
297
+
298
+ if (link.is(rails.linkDisableSelector)) rails.disableElement(link);
299
+
300
+ if (link.data('remote') !== undefined) {
301
+ if ( (e.metaKey || e.ctrlKey) && (!method || method === 'GET') && !data ) { return true; }
302
+ rails.handleRemote(link);
303
+ return false;
304
+ } else if (link.data('method')) {
305
+ rails.handleMethod(link);
306
+ return false;
307
+ }
308
+ });
309
+
310
+ $(rails.inputChangeSelector).live('change.rails', function(e) {
311
+ var link = $(this);
312
+ if (!rails.allowAction(link)) return rails.stopEverything(e);
313
+
314
+ rails.handleRemote(link);
315
+ return false;
316
+ });
317
+
318
+ $(rails.formSubmitSelector).live('submit.rails', function(e) {
319
+ var form = $(this),
320
+ remote = form.data('remote') !== undefined,
321
+ blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector),
322
+ nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
323
+
324
+ if (!rails.allowAction(form)) return rails.stopEverything(e);
325
+
326
+ // skip other logic when required values are missing or file upload is present
327
+ if (blankRequiredInputs && form.attr("novalidate") == undefined && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
328
+ return rails.stopEverything(e);
329
+ }
330
+
331
+ if (remote) {
332
+ if (nonBlankFileInputs) {
333
+ return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
334
+ }
335
+
336
+ // If browser does not support submit bubbling, then this live-binding will be called before direct
337
+ // bindings. Therefore, we should directly call any direct bindings before remotely submitting form.
338
+ if (!$.support.submitBubbles && rails.callFormSubmitBindings(form) === false) return rails.stopEverything(e);
339
+
340
+ rails.handleRemote(form);
341
+ return false;
342
+ } else {
343
+ // slight timeout so that the submit button gets properly serialized
344
+ setTimeout(function(){ rails.disableFormElements(form); }, 13);
345
+ }
346
+ });
347
+
348
+ $(rails.formInputClickSelector).live('click.rails', function(event) {
349
+ var button = $(this);
350
+
351
+ if (!rails.allowAction(button)) return rails.stopEverything(event);
352
+
353
+ // register the pressed submit button
354
+ var name = button.attr('name'),
355
+ data = name ? {name:name, value:button.val()} : null;
356
+
357
+ button.closest('form').data('ujs:submit-button', data);
358
+ });
359
+
360
+ $(rails.formSubmitSelector).live('ajax:beforeSend.rails', function(event) {
361
+ if (this == event.target) rails.disableFormElements($(this));
362
+ });
363
+
364
+ $(rails.formSubmitSelector).live('ajax:complete.rails', function(event) {
365
+ if (this == event.target) rails.enableFormElements($(this));
366
+ });
367
+
368
+ })( jQuery );
369
+ "content_type"application/javascript"
370
+ class"BundledAsset"
371
+ mtime"2011-11-13T18:12:14-05:00"
372
+ mtimeIu: Time