Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Don't break validations yo!

  • Loading branch information...
commit 5431b30bb9da0fed8df8d62213a30bf4885afd45 1 parent c2ac076
Pat Nakajima authored
1  app/controllers/bookmarklets_controller.rb
@@ -47,7 +47,6 @@ def authorize
47 47 # POST /bookmarklets.xml
48 48 def create
49 49 @bookmarklet = Bookmarklet.new(params[:bookmarklet])
50   -
51 50 respond_to do |format|
52 51 if @bookmarklet.save
53 52 flash[:notice] = 'Your bookmarklet was successfully created!'
9 app/models/bookmarklet.rb
@@ -12,6 +12,10 @@ def spam?
12 12 end
13 13
14 14 def code
  15 + self[:code]
  16 + end
  17 +
  18 + def code_with_jquery
15 19 if jquery?
16 20 jquery = <<-JS
17 21 var _jq = document.createElement('script');
@@ -24,15 +28,16 @@ def code
24 28 wrapped_code = <<-JS
25 29 window.setTimeout(function() {
26 30 jQuery.noConflict();
27   - #{self[:code]}
  31 + #{code_without_jquery}
28 32 }, 10);
29 33 JS
30 34
31 35 [jquery, wrapped_code].join("\n")
32 36 else
33   - self[:code]
  37 + code_without_jquery
34 38 end
35 39 end
  40 + alias_method_chain :code, :jquery
36 41
37 42 def highlighted_code
38 43 self[:highlighted_code] || begin

0 comments on commit 5431b30

Please sign in to comment.
Something went wrong with that request. Please try again.