Method: Merb::Router.resource

Defined in:
lib/merb-core/dispatch/router.rb

.resource(*args) ⇒ Object

Generates a URL from the resource(s)

Parameters

resources<Symbol,Object>

The identifiers for the resource route to generate. These can either be symbols or objects. Symbols denote resource collection routes and objects denote the members.

params<Hash>

Any extra parameters needed to generate the route.

Returns

String

The generated URL




168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/merb-core/dispatch/router.rb', line 168

def resource(*args)
  defaults = args.pop
  options  = extract_options_from_args!(args) || {}
  key      = []
  params   = []

  args.each do |arg|
    if arg.is_a?(Symbol) || arg.is_a?(String)
      key << arg.to_s
    else
      key << arg.class.to_s
      params << arg
    end
  end

  params << options

  unless route = Merb::Router.resource_routes[key]
    raise Merb::Router::GenerationError, "Resource route not found: #{args.inspect}"
  end

  route.generate(params, defaults)
end