V
V
Vayladion Gognazdiak2014-12-18 10:45:04
Ruby on Rails
Vayladion Gognazdiak, 2014-12-18 10:45:04

Where is the error in Rails routing?

Good day.
There is ruby ​​2.1.5 and rails 4.1.8.
The application returns in JSON the data previously entered manually in the admin panel.
api.test.com/subscribtions - JSON returned /api/subscribtions_controller.rb
test.com/subscribtions - list returned /subscribtions_controller.rb
When I try to go to / ( welcome_controller )
I get the error:
Started GET "/" for 10.0.0.21 at 2014 -12-18 10:40:13 +0300
Processing by WelcomeController#index as HTML
Rendered welcome/index.html.erb within layouts/application (229.6ms)
Completed 500 Internal Server Error in 362ms
ActionView::Template::Error (Response from the API must behave like a Hash or an Array (last JSON response was "HTTP Basic: Access denied.\n")):
2:
3: <%= t('subscribtions' ) %>
4:
5: <%= render @subscribtions -%>
6:
7:
8:
config/initializers/her.rb:13:in `call'
app/views/welcome/index.html.erb:5: in `_app_views_welcome_index_html_erb___4542053705226696085_70232745016520' Works with

the controller from /api, although the normal one should work.
Where to dig?
Thanks in advance for your replies.
The routes.rb listing and views are below.

.jumbotron
  %h1 Главная
  %hr
  %p Количество Продуктов (#{Product.count})
  %p Количество Проектов (#{Project.count})
  %hr
  %p
    = link_to 'Продукты', products_path, class: 'btn btn-lg btn-primary'
    = link_to 'Проекты', projects_path, class: 'btn btn-lg btn-primary'
    = link_to 'Категории', categories_path, class: 'btn btn-lg btn-primary'
    = link_to 'Подписки', subscribtions_path, class: 'btn btn-lg btn-primary'

routes.rb
Plan::Application.routes.draw do
  root 'welcome#index'
  scope module: :api do
    constraints subdomain: /(api|test)(.*)/ do
      
      resources :subscribtions do
        member do
        resources :categories do
          member do
            resources :products
          end
        end
      end
      end
      resources :categories, :products
    end
  end

  resources :signed_urls, only: :index 
  resources :projects, :categories, :products
  resources :subscribtions do
    member do
      get :send_to_trash
    end
  end
  match "/delayed_job" => DelayedJobWeb, :anchor => false, via: 'get'
end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Polushkin, 2015-02-12
@dmitry-polushkin

Use the `namespace` DSL command. More here: guides.rubyonrails.org/routing.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question