route :get, :delete, :post, :put, '/*/*?/?*?' do |model, action, id|

41 views
Skip to first unread message

darthophage

unread,
May 1, 2012, 2:46:57 AM5/1/12
to sinatrarb
route :get, :delete, :post, :put, '/*/*?/?*?' do |model, action, id|
# some code
end

Then, when I navigate to http://localhost/something/something/something

puts model # ="something"
puts action # =""
puts id # =""

I need to have the splats to collect anything written between / /
and also the optional ? commands for the splats and /

does the optional command splat's collection?
How do I do this properly?

Carlos Eduardo L. Lopes

unread,
May 2, 2012, 9:54:33 AM5/2/12
to sina...@googlegroups.com
Sorry, i tested the regex and it's wrong, this should fix it

%r{/(?<model>[a-z]*)(?:/(?<action>[a-z]*))?(?:/(?<id>[1-9][0-9]*))?}

On Wed, May 2, 2012 at 10:42 AM, Carlos Eduardo L. Lopes <carlos....@gmail.com> wrote:
I would do this using Regexp, for me it's the better way.

something like:

route :get, :delete, :post, :put, %r{/(?<model>.*)(?:/(?<action>.*))?(?:/(?<id>[1-9][0-9]*))?} do ...

I didn't test this code, but i think it will work



--
You received this message because you are subscribed to the Google Groups "sinatrarb" group.
To post to this group, send email to sina...@googlegroups.com.
To unsubscribe from this group, send email to sinatrarb+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sinatrarb?hl=en.




--
Carlos Eduardo L. Lopes
Skype: carloslopespollares | Twitter: @_carloslopes





--
Carlos Eduardo L. Lopes
Skype: carloslopespollares | Twitter: @_carloslopes


Carlos Eduardo L. Lopes

unread,
May 2, 2012, 9:42:56 AM5/2/12
to sina...@googlegroups.com
I would do this using Regexp, for me it's the better way.

something like:

route :get, :delete, :post, :put, %r{/(?<model>.*)(?:/(?<action>.*))?(?:/(?<id>[1-9][0-9]*))?} do ...

I didn't test this code, but i think it will work

On Tue, May 1, 2012 at 3:46 AM, darthophage <darth...@sympatico.ca> wrote:
--
You received this message because you are subscribed to the Google Groups "sinatrarb" group.
To post to this group, send email to sina...@googlegroups.com.
To unsubscribe from this group, send email to sinatrarb+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sinatrarb?hl=en.

Reply all
Reply to author
Forward
0 new messages