This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
URI.parse(response.redirect_url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rack::Utils.parse_query(URI.parse(response.redirect_url).query)["param"].should == "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CGI.parse(URI.parse(response.redirect_url).query) if URI.parse(response.redirect_url).query.present? | |
=> {"x"=>["1"], "y"=>["2"]} | |
Rack::Utils.parse_query(URI.parse(response.redirect_url).query | |
=> {"x"=>"1", "y"=>"2"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
response.should redirect_to named_route_path(resource.id, :param => "true") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
belongs_to :job, :class_name => "Delayed::Backend::ActiveRecord::Job" | |
# full path name required if you're in another module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bit.ly API implementation - thanks to Richard Johansso http://gist.github.com/112191 | |
require 'httparty' | |
class Api::Bitly | |
include HTTParty | |
base_uri 'api.bit.ly' | |
format :json | |
# Usage: Bitly.shorten("http://example.com") | |
def self.shorten(url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyModel < ActiveRecord::Base | |
before_create lambda { | |
action_1 | |
action_2 | |
} | |
def action_1 | |
self.mydata = "default" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyModel < ActiveRecord::Base | |
before_create :action_1 | |
before_create :action_2 # might depend on action_1 | |
def action_1 | |
self.mydata = "default" | |
end | |
def action_2 | |
self.mycomplexdata = default + "more data" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update | |
@my_model = MyModel.find_by_id(params[:id]) | |
params[:my_model].try(:[], "my_value_array").try(:reject!){|v| v.blank? } | |
if @my_model.update_attributes(params[:my_model]) | |
# blah blah blah | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# my_value_array :text | |
class MyModel < AciveRecord::Base | |
serialize :my_value_array, Array | |
end |