Skip to content

Instantly share code, notes, and snippets.

@stevenbristol
stevenbristol / gist:3135798
Created July 18, 2012 12:04
customizing a confirmation box
$.rails.allowAction = (link) ->
return true unless link.attr('data-confirm')
$.rails.showConfirmDialog(link) # look bellow for implementations
false # always stops the action since code runs asynchronously
$.rails.confirmed = (link) ->
link.removeAttr('data-confirm')
link.trigger('click.rails')
@stevenbristol
stevenbristol / gist:2917558
Created June 12, 2012 13:38
BigDecimal to_json as string
This doc:
http://api.rubyonrails.org/classes/BigDecimal.html#method-i-as_json
says:
A BigDecimal would be naturally represented as a JSON number. Most libraries, however, parse non-integer JSON numbers directly as floats. Clients using those libraries would get in general a wrong number and no way to recover other than manually inspecting the string with the JSON code itself.
That’s why a JSON string is returned. The JSON literal is not numeric, but if the other end knows by contract that the data is supposed to be a BigDecimal, it still has the chance to post-process the string and get the real value.
class Business
many :invoices
end
class Invoice
property :ref, String
property :total, BigDecimal
property :paid_total, BigDecimal
one :buinsess
I think it's ok to replace:
self.send(:update_without_callbacks)
with:
LineItem.skip_callback(:save) {save}
class PostsController < ActionController::Base
def create
SomePOROThatDoesNotDependOnRails.run(params)
end
def update
SomePOROThatDoesNotDependOnRails.run(params)
end
private
Using ts 1.3.16 on a rails 2.3.8 app:
Here is the index:
define_index do
indexes name, :sortable=>:true
indexes zip
>>>> This is a normal request to the url via a browser:
Started GET "/api/bulk?events=all" for 127.0.0.1 at Wed Oct 19 09:56:48 -0400 2011
Processing by Bulk::ApiController#get as HTML
Parameters: {"events"=>"all"}
Event Load (0.6ms) SELECT `events`.* FROM `events` LIMIT 100
Completed 200 OK in 289ms (Views: 105.6ms | ActiveRecord: 0.6ms | Sphinx: 0.0ms)
class Bike
def price
send "price_for_#{@bike_type}"
end
def price_for_a
end
def price_for_b
diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_d
index 24ebb8f..206959b 100644
--- a/actionpack/lib/action_dispatch/middleware/cookies.rb
+++ b/actionpack/lib/action_dispatch/middleware/cookies.rb
@@ -167,7 +167,7 @@ module ActionDispatch
handle_options(options)
- @set_cookies[key] = options
+ @set_cookies[key.to_s] = options
module ActionDispatch
class Cookies
class CookieJar < Hash #:nodoc:
# Sets the cookie named +name+. The second argument may be the very cookie