ruby - How do I change the location of a path after create in Rails? -


i have routes.rb file looks this:

namespace :api  namespace :v1   resources :posts, except: [:new, :edit]  end end 

this lets me generate urls "mywebsite.com/api/v1/posts" instead of "mywebsite.com/posts" default.

my create method looks this:

def create     @post = post.new(params[:post])      if @post.save       render json: @post, status: :created, location: @post     else       render json: @post.errors, status: :unprocessable_entity     end end 

the location: @post worked great until namespaced urls. how can location: @post reflect changes?

location: api_v1_post_path(@post)


Comments