B
B
bismoney2015-10-26 16:33:41
Ruby on Rails
bismoney, 2015-10-26 16:33:41

How to do the right routing?

Hi friends.
I can't figure out what the problem is.
Made impoverishment in the admin panel

namespace :admin do
  resources :posts
  devise_for :users
end

I did this for the site (so that it would be more convenient to structure everything by folders)
And I limited the posts to only Index and Show
scope module: 'site' do
  resources :posts, only: [:index, :show] 
  root 'main#index'
end

And everything seems to be working fine.
The site is ok. But in the admin panel, the cant is this:
After filling in a new post and clicking create post, I am redirected here
site.ru/posts
And the error is
No route matches [POST] "/posts"
Why does it not route properly to site.ru/admin/posts ?
Tell me please.
UDP all route
Rails.application.routes.draw do

# admin area
get "/admin" => "admin/main#index"

scope module: 'site' do
  resources :posts, only: [:index, :show] 
  root 'main#index'
end

namespace :admin do
  resources :posts
  devise_for :users
end

end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Veniamin Chebotarev, 2015-10-26
@bismoney

What do you have in the create action? Redirect to posts_path ? Redirect to admin_posts_path

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question