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
Related
I am developing a rails app and This is my first time working with ruby or any server-side programming language. I connected to localhost:3000 and everything went well. I went to change the routing for my home page as well as create some new ones but I'm having an issue of gettign them to preview and I keep Getting error messages. Here is the snippet from my routes.rb file
My routes.rb
Rails.application.routes.draw do
root 'pages#home'
get 'about' => 'pages#about'
post 'forum' => 'pages#forum'
get 'contact-us' => 'pages#contact-us'
end
I'm still relatively new To programming as well as stack overflow so I can't embed images yet So it will only have a link. Any help would be appreciated. Thank you!
1 - Try to avoid fat arrow
2- Controller name should not contain -(dash) instead use _(Underscore) example(contact-us should be contact_us)
Rails.application.routes.draw do
root 'pages#home'
get '/about', to: 'pages#about', as: :about
post '/forum', to: 'pages#forum', as: :forum
get '/contact_us', to: 'pages#contact_us', as: :contact_us
end
3- After changing this run rake routes at your console in your project directory , you will get list of routes
4- you can now use routes helper of prefix_path example (root_path, about_path or forum_path, contact_path)
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.
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
When navigating to localhost:3000, I want to navigate to: localhost:3000/workers.
So I changed public/index.html to public/index.html.bak and in routes.rb, I defined the next followings:
devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy' end
resources :tasksadmins
resources :workers
root to: "workers#index"
However, it doesn't work. The page localhost:3000 shows me the Welcome aboard page.
How can I fix it? Any help appreciated.
Seems fine. Have you restarted the server?
For my rails 3 app I have a route setup as follows
namespace :user do
root :to => "reading_schedules#index"
end
This is what my "rake routes" shows
user_root /user(.:format) {:controller=>"user/reading_schedules", :action=> "index }
Everything works fine on my localmachine. But as soon as I push the site up to Heroku and login I get the following error in my logs
ActionController::RoutingError (uninitialized constant User::ReadingSchedulesController):
If I navigate to the root of the site everything else works fine. But this one url doesn't work. The url it's trying to hit is website/user but like I said, it works fine on my localmachine.
EDIT:
Here's the rest of my routes file
devise_for :users, :path => 'accounts'
root :to => "home#landing"
namespace :user do
root :to => "reading_schedules#index"
end
resources :users do
resources :reading_schedules
member do
get :change_password
post :change_password
end
end
resources :reading_schedules do
member do
get :recalculate
end
end
I found this question first in looking for an answer to the same issue. For any future searchers, check out this link.
For me, it was a combination of the last two answers in this post (adapted for my controllers of course.)
Also of note, this corrected the issue without having to reset the database.
ActionController::RoutingError (uninitialized constant User::UsersController) in heroku (but everything works in local)
Probably not the answer you are looking for but
heroku rake db:reset
solved the problem for me. I didn't have any critical data in the
db so it was not a problem.