How to prevent pipe character from causing a Bad URI Error in Rails 3/Ruby 1.9.2?
I ran into the same requirement (and problem) recently. On Rails 3 and Ruby 1.9.2.
It is not a problem for our staging/production environment (nginx), but I was interested to find out what the problem was with WEBrick. Turns out the issue is down in the URI::Parser.split method, specifically how it's pattern matching is seeded with the URI::REGEXP::PATTERN constants.
You can "fix" this by adding the following to a config/environments/development.rb (assuming you'd only be using WEBrick in dev .. or you could put it in a config/initializers file)..
# this allows WEBrick to handle pipe symbols in query parameters
URI::DEFAULT_PARSER =
URI::Parser.new(:UNRESERVED => URI::REGEXP::PATTERN::UNRESERVED + '|')
NB: that's setting :UNRESERVED => "-_.!~*'()a-zA-Z\d|"
Bad Request/Bad URI on production (Heroku) but not locally
Switching from Webrick to Thin on Heroku resolved this issue, though I'm not sure about the specifics as to why.
Bad Request/Bad URI on production (Heroku) but not locally
Switching from Webrick to Thin on Heroku resolved this issue, though I'm not sure about the specifics as to why.
Extract data from URL
I think this might work well for you as it identifies the leading name as well:
url_parts = uri.path.scan(/\/(\w+)\/(\d+)/)
#=> [["test","1"],["direction","2"]]
Then you could even make it a Hash
using:
Hash[url_parts]
#=> {"test" => "1", "direction" => "2"}
Find two consecutive rows
Assuming the rows have sequential IDs, something like this may be what you're looking for:
select top 1 *
from
Bills b1
inner join Bills b2 on b1.id = b2.id - 1
where
b1.IsEstimate = 1 and b2.IsEstimate = 1
order by
b1.BillDate desc
Related Topics
Define_Method: How to Dynamically Create Methods with Arguments
How to Loop Through a Daterange with Different Intervals
Differencebetween Ruby's Send and Public_Send Methods
Backspace and Arrow Keys Aren't Working in Irb(Git Bash Console) on Windows MAChine
Differencebetween 'Include' and 'Prepend' in Ruby
What's the Difference Between Bundle.Setup and Bundle.Require
Rendering Haml Partials from Within Haml Outside of Rails
Printing to Screen in a Rake Task
Rails Previous Sunday in Relation to Any Datetime
Circular Dependency Detected While Autoloading Constant When Loading Constant
Resetting a Singleton Instance in Ruby
How to Use Rspec Expectations in Irb