Active Admin has taken over my routes completely - ruby-on-rails

im building a basic ecommerce app to teach myself rails, and ive hit a problem. I had already installed devise and had two user models: 'users' and 'merchants'. I then installed active_admin and setup it's standard 'admin_user' model.
The admin section works as intended however now the view of every resource that active admin has access to has become the admin version.
Even my root now routes to the active admin login (assuming no one's logged in)
Any ideas as to why this is happening?
devise_for :merchants
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
devise_for :users
resources :products
resources :categories
resources :brands
get "static/about"
get "static/contact"
get "static/cookie"
get "static/faq"
get "static/help"
get "static/index"
get "static/privacy"
get "static/terms"
root :to => 'static#index'

The order in which rails parses route priority is from top to bottom so, first created -> highest priority. Active Admin also has a root :to => 'admin#dashboard route so your app is trying to load that as the main root route right now.
Try moving ActiveAdmin.routes(self) below your root :to => 'static#index'

Related

Can't deploy app on heroku, always get "The page you were looking for doesn't exist." error

Hi I'm trying to deploy an app made with help of "Agile web development by S.Ruby" and I always get the same error - The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.
I've already tried to migrate my DB on Heroku - that wasn't the case.I think something is wrong with routes.rb file, but I can't understand what is incorrect exactly,please help me to solve this problem
Here is my routes.rb file:
Depot::Application.routes.draw do
get 'admin' => 'admin#index'
controller :sessions do
get 'login' => :new
post 'login' => :create
delete 'logout' => :destroy
end
get "sessions/create"
get "sessions/destroy"
resources :users
resources :products do
get :who_bought, on: :member
end
scope '(:locale)' do
resources :orders
resources :line_items
resources :carts
root 'store#index', as: 'store', via: :all
end
end
As Michal correctly points out you miss the root path. You have defined a route inside the scope you use to get to the different locales, but not a global root. This is not a Heroku problem, it won't work on your local server either.
So, http://your_server.com/en will work, but http://your_server.com will not.
You need to add a root path outside all scopes, like so:
root 'store#index'
You will have to set a default locale or something like that. You can leave the other root directive inside the scope, as you have named it explicitly (with as: 'store') there won't be any conflict.

Sometimes getting an "Invalid Route Name" Error in Rails

I am getting the following error only on occasion when I attempt to load up my Rails app in localhost.
Invalid route name, already in use: 'root' You may have defined two routes with the same name using the :as option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with resources as explained here: http://guides.rubyonrails.org/routing.html#restricting-the-routes-created
For some reason, it only happens every now and again, and generally goes away after I refresh the page once. The file it is calling into question has this as the code (line causing the error indicated):
Rails.application.routes.draw do
get 'welcome/index'
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
Rails.application.routes do
resources :articles
root 'welcome#index' #-->This is the line that causes the error
end
resources :articles do
resources :comments
end
end
I am really new to Rails, and I'm not sure what is causing the problem or if would even be a problem if I were to actually host this beginner project on the web. Also, if it helps, I am running Ruby 2.2.2 and Rails 4.2.1.
Thank you in advance for the help!
You have (Rails.application.routes) nested inside (Rails.application.routes.draw). Run rake routes and you will see that you have resources for articles twice. Furthermore, you have root 'welcome#index' nested inside and that is why you are getting the error. Your routes should look like this
Rails.application.routes.draw do
get 'welcome/index' => 'welcome#index'
root 'welcome#index'
resources :articles do
resources :comments
end
end
Note that the route of your application meaning(/) and (/welcome/index) both point to the welcome controller index action. You don't really need get 'welcome/index' => 'welcome#index' and you can delete that line and use root when ever you need the index action from the welcome controller.
Try using the "Full" syntax.
root :to=> "some#action"
You have two routes pointing to the same page index, get rid of your get route
get 'welcome/index'
Also your root route is nested that should be moved outside since the root route is the root of your entire app and not a specific resource

set devise users/sign_up page as landing page

I'm new to rails and I'm using devise to authenticate users.
I have a devise User model and I'm using devise views.
my routes.rb file goes like this
Freshconnection::Application.routes.draw do
root to: 'pages#home'
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
devise_for :users do
ActiveAdmin.routes(self)
get '/users/sign_out' => 'devise/sessions#destroy'
end
As of now when I run the server, the request is routed to pages#home which is my landing page.
I want the users/sign_up page to be the landing page so that the user can sign_up and start using the website.
Please guide me on how this has to be accomplished.
Many thx
As described here (link) you could try the workaround
devise_scope :user do
root to: "devise/registrations#new"
end
Change your root directive to:
root to: 'devise/registrations#new'

Route appears in rake routes, but not on site

I'm new to ruby on rails, and I'm having trouble getting up to speed. I've set up devise for user authentication, and everything seemed to be going well. Until I tried to get routes set up
Basically, I've deleted my /public/index.html, and I've set a new default route. Here's my /config/routes.rb
MyApp::Application.routes.draw do
authenticated :user do
root :to => 'home#index'
end
root :to => "home#index"
devise_for :users
end
Okay, so that seems simple enough. I generated a home controller/view. My index.html.erb is just the default. My controller is also blank.
When I run rake routes, I can see the route to the root.
root / home#index
root / home#index
So this seems like a go! But...It's not. I get an error when I try and open my index
No route matches [GET] "/"
I don't feel like the details of my server should be significant, but it's nginx. I can post my server configuration if anyone thinks it's important.
Blargh. I'm an idiot. The server configuration I though wouldn't matter was the problem. I had edited my nginx settings, but I left the default in Unicorn. I never noticed before now, since the /public/index.html in both the unnecessary app and my app were the same. Thanks for all the help though.
You should be add resources :homes
MyApp::Application.routes.draw do
resources :homes
root :to => "home#index"
devise_for :users
end

Using on_the_spot gem immediately logs out user

I have finally gotten the on_the_spot gem working in my rails app, which uses devise for authentication.
But, when a user is logged in, making an edit on the user 'show' page results in them being immediately logged out after the change is made (and saved). My guess is that this is to do with routes.rb?
get "users/index"
get "users/show"
devise_for :users, :controllers => { :registrations => :registrations }
devise_for :users
resources :users
root :to => "home#index"
match '/:id' => 'users#show'
resources :users do
collection do
post :update_attribute_on_the_spot
end
end
Are there any obvious errors in this that would cause my problem? Or should I be looking elsewhere? I'm using Rails 3.0.10 and the latest versions of Devise/on_the_spot.
Many thanks!

Resources