Permalink
Browse files

updates for the removal of ActionController::AbstractRequest

  • Loading branch information...
1 parent feed6c6 commit b0c391953e6c8388d96a54260c165fea4606fb31 @UnderpantsGnome committed Apr 3, 2009
Showing with 36 additions and 12 deletions.
  1. +7 −2 lib/core_extensions.rb
  2. +29 −10 lib/rails_extensions.rb
View
@@ -13,15 +13,20 @@ def only(*keys)
!keys.include? k.to_sym
}
end
+
+ # allows you to use { :val => 'foo' }.val #=> "foo"
+ def method_missing(key)
+ has_key?(key) || has_key?(key.to_s) ? self[key] || self[key.to_s] : super
+ end
end
class Array
def shuffle
dup.shuffle!
- end
+ end
def shuffle!
- each_index do |i|
+ each_index do |i|
j = rand(length-i) + i
self[j], self[i] = self[i], self[j]
end
View
@@ -9,9 +9,17 @@ def boolean_field(*args)
end
module ActionController
- class AbstractRequest
- def referrer
- self.env['HTTP_REFERER']
+ begin
+ class AbstractRequest
+ def referrer
+ self.env['HTTP_REFERER']
+ end
+ end
+ rescue
+ class AbstractRequest
+ def referrer
+ self.env['HTTP_REFERER']
+ end
end
end
@@ -20,10 +28,21 @@ class << self
def simple_action(*actions)
actions.each {|action| class_eval("def #{action}; end")}
end
-
+
def forbidden_action(*actions)
- actions.each {|action|
- class_eval("def #{action}; render :nothing => true, :status => :forbidden; end")
+ actions.each {|action|
+ class_eval(
+ <<-EOEVAL
+ def #{action}
+ respond_to do |format|
+ format.html { render :status => :forbidden, :template => '/shared/forbidden' }
+ format.xml { render :nothing => true, :status => :forbidden }
+ format.json { render :nothing => true, :status => :forbidden }
+ format.xhr { render :nothing => true, :status => :forbidden }
+ end
+ end
+ EOEVAL
+ )
}
end
end
@@ -33,18 +52,18 @@ def forbidden_action(*actions)
module ApplicationHelper
module_eval do
def stylesheet_controller_tag
- stylesheet_link_tag(controller.controller_name) if
+ stylesheet_link_tag(controller.controller_name) if
public_file_exists?(stylesheet_path(controller.controller_name))
end
def javascript_controller_tag
- javascript_include_tag(controller.controller_name) if
+ javascript_include_tag(controller.controller_name) if
public_file_exists?(javascript_path(controller.controller_name))
end
def javascript_action_tag
name = "#{controller.controller_name}_#{controller.action_name}"
- javascript_include_tag(name) if
+ javascript_include_tag(name) if
public_file_exists?(javascript_path(name))
end
@@ -67,7 +86,7 @@ def distance_of_time_for(obj, method)
"<span style=\"display:none\">object does not respond to #{method}</span>"
end
end
-
+
def back_link(text='Back', *args)
link_to text, (request.referrer || 'javascript:history.go(-1)'), *args
end

0 comments on commit b0c3919

Please sign in to comment.