Added support for URLs with placeholder arguments #4

Open
wants to merge 2 commits into
from

Conversation

Projects
None yet
2 participants
@umjames

umjames commented Nov 24, 2011

In Sinatra, you can specify a URL pattern handler such as /object/:id that will match URLs like /object/1 or /object/5.

I added support for this type of URL to be specified in the URL argument to url_for. If url_for's options argument has a key that equals the placeholder, the value associated with that key will be substituted into the url and that argument is removed from the options.

I added 2 rspec examples that show how this works.

umjames added some commits Nov 23, 2011

Running the spec task was giving errors that it could not find
rack/test.  Fixed this by adding the gem to the Gemfile in the test
group and requiring the gems in that group in spec/spec_helper.rb.

Also fixed the rake/rdoctask deprecation warning by adding the rdoc gem
to the gem file and requiring rdoc/task in the Rakefile.
+
+ options_used = Set.new
+
+ options.each_pair do |placeholder_name, value|

This comment has been minimized.

Show comment Hide comment
@gregretkowski

gregretkowski Jul 2, 2014

There's a bug here - method url_for sets options to nil unless options was passed in. So if you don't pass in the optional parameter options you get "undefined method each_pair for nil:NilClass". BTW - the bug above is present in the version obtained from rubygems.org via 'gem install sinatra-url-for"

@gregretkowski

gregretkowski Jul 2, 2014

There's a bug here - method url_for sets options to nil unless options was passed in. So if you don't pass in the optional parameter options you get "undefined method each_pair for nil:NilClass". BTW - the bug above is present in the version obtained from rubygems.org via 'gem install sinatra-url-for"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment