Trying to implement web service in rails through API sub-domain called "api". In my hosts file i added line: 127.0.0.1 api.localhost In my routes.rb i set sub-domain, where i only need index action and few manually added restful routes, through following: namespace :api, path: '''', :constraints => {:subdomain => "api"} do resources :posts, only: :index do collection do get ''popular_by_day'' get ''popular_by_week'' end endend Also generated coresponding controller with: rails g controller api/posts *Test example:* class Api::PostsController < ApplicationController def index @posts = 1 respond_to do |format| format.json { render :json => @posts } end end def popular_by_day end def popular_by_week endend After rake routes i have following: popular_by_day_api_posts GET /posts/popular_by_day(.:format) api/posts#popular_by_day {:subdomain=>"api"} popular_by_week_api_posts GET /posts/popular_by_week(.:format) api/posts#popular_by_week {:subdomain=>"api"} api_posts GET /posts(.:format) api/posts#index {:subdomain=>"api"} Far as i know, link to http://api.localhost:3000/posts should work but i get routing error: *No route matches [GET] "/posts"* (Same with /posts.json) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f6ef7dce-2263-44c3-b7f7-cdadc2787d0b%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
On Nov 20, 2013, at 4:04 AM, Srdjan Cengic <cengasrle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Far as i know, link to http://api.localhost:3000/posts should work but i get routing error: > No route matches [GET] "/posts" (Same with /posts.json)This isn’t how localhost works, at all. If you need to set up a local subdomain for testing, you most likely will need to do things like modify your /etc/hosts table, set up local DNS resolvers, and the like. If you’re running on a mac, you can use pow, which makes all that dead-easy. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/367ECB72-D8B2-45DC-82AC-3138A2314E89%40gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
On 2013-Nov-21, at 04:12 , Tamara Temple <tamouse.lists-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On Nov 20, 2013, at 4:04 AM, Srdjan Cengic <cengasrle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> Far as i know, link to http://api.localhost:3000/posts should work but i get routing error: >> No route matches [GET] "/posts" (Same with /posts.json) > > This isn’t how localhost works, at all. > > If you need to set up a local subdomain for testing, you most likely will need to do things like modify your /etc/hosts table, set up local DNS resolvers, and the like. If you’re running on a mac, you can use pow, which makes all that dead-easy.But you could use: http://api.127.0.0.1.xip.io:3000/posts See http://xip.io/ for the details, but this will resolve to the IP address before the .xip.io and then api will be the subdomain. -Rob -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9BD1A639-67DB-4C89-B098-E725D897B52C%40gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
On Nov 21, 2013, at 5:37 AM, Rob Biedenharn <rob.biedenharn-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 2013-Nov-21, at 04:12 , Tamara Temple <tamouse.lists-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> >> On Nov 20, 2013, at 4:04 AM, Srdjan Cengic <cengasrle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>> Far as i know, link to http://api.localhost:3000/posts should work but i get routing error: >>> No route matches [GET] "/posts" (Same with /posts.json) >> >> This isn’t how localhost works, at all. >> >> If you need to set up a local subdomain for testing, you most likely will need to do things like modify your /etc/hosts table, set up local DNS resolvers, and the like. If you’re running on a mac, you can use pow, which makes all that dead-easy. > > But you could use: > http://api.127.0.0.1.xip.io:3000/posts > > See http://xip.io/ for the details, but this will resolve to the IP address before the .xip.io and then api will be the subdomain. > > -Rob+++Rob. I didn’t know about xip.io, thanks! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/C8E528CE-7D63-4F4A-B57C-27BBDED3D414%40gmail.com. For more options, visit https://groups.google.com/groups/opt_out.