Full url for an image-path in Rails 3

You can also set CarrierWave’s asset_host configĀ setting like this: # config/initializers/carrierwave.rb CarrierWave.configure do |config| config.storage = :file config.asset_host = ActionController::Base.asset_host end This ^ tells CarrierWave to use your app’s config.action_controller.asset_host setting, which can be defined in one of your config/envrionments/[environment].rb files. See here for more info. Or set it explicitly: config.asset_host=”http://example.com” Restart your app, and …

Read more

Regular expression for URL validation (in JavaScript)

In the accepted answer bobince got it right: validating only the scheme name, ://, and spaces and double quotes is usually enough. Here is how the validation can be implemented in JavaScript: var url=”http://www.google.com”; var valid = /^(ftp|http|https):\/\/[^ “]+$/.test(url); // true or var r = /^(ftp|http|https):\/\/[^ “]+$/; r.test(‘http://www.goo le.com’); // false or var url=”http:www.google.com”; var …

Read more

Rails ArgumentError: invalid %-encoding

if you don’t mind against monkeypatching Rack then create in config/initializers file (for example rack.rb) with this content: module Rack module Utils if defined?(::Encoding) def unescape(s, encoding = Encoding::UTF_8) begin URI.decode_www_form_component(s, encoding) rescue ArgumentError URI.decode_www_form_component(URI.encode(s), encoding) end end else def unescape(s, encoding = nil) begin URI.decode_www_form_component(s, encoding) rescue ArgumentError URI.decode_www_form_component(URI.encode(s), encoding) end end end module_function …

Read more

Create URL from a String

URL url = new URL(yourUrl, “/api/v1/status.xml”); According to the javadocs this constructor just appends whatever resource to the end of your domain, so you would want to create 2 urls: URL domain = new URL(“http://example.com”); URL url = new URL(domain + “/files/resource.xml”); Sources: http://docs.oracle.com/javase/6/docs/api/java/net/URL.html

Getting “java.net.ProtocolException: Server redirected too many times” Error

It’s apparently redirecting in an infinite loop because you don’t maintain the user session. The session is usually backed by a cookie. You need to create a CookieManager before you use URLConnection. // First set the default cookie manager. CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); // All the following subsequent URLConnections will use the same cookie manager. URLConnection …

Read more