Started working with RoR again! I'm having trouble getting my config/routes.rb file to perform. I'm getting "uninitialized constant ApplicationsController" using RubyMine.
Here's what I have changed in my routes.rb after trying to search things down:
resources :applications
root :to => 'applications#index'
application_controller.rb has:
class ApplicationController < ActionController::Base
protect_from_forgery
end
I've ran my rake routes:
applications GET /applications(.:format) applications#index
POST /applications(.:format) applications#create
new_application GET /applications/new(.:format) applications#new
edit_application GET /applications/:id/edit(.:format) applications#edit
application GET /applications/:id(.:format) applications#show
PUT /applications/:id(.:format) applications#update
DELETE /applications/:id(.:format) applications#destroy
root / applications#index
rake rails:update and all changes were approved except altering routes.rb
Heres what its kicks out Rubymine side:
Started GET "/" for 127.0.0.1 at 2012-11-11 02:50:27 -0800
Connecting to database specified by database.yml
ActionController::RoutingError (uninitialized constant ApplicationsController):
Thanks for the help!
You should rename application_controller.rb to applications_controller.rb
Check if you have a file called applications_controller in your app/controller folder, or its name is application_controller, so rename it to applications_controller, if you don't have that file, then create your ApplicationsController:
rails generate controller applications
Related
Server: Rails 3.1.10 and Ruby 1.9.2 on Ubuntu 11.10 (Oneiric). Client: Windows 7, Chrome 29.0.1547.66 m.
I have a small but annoying problem: checking my logs, I see that my homepage loads twice. Strangely though, it works correctly (loads only once) if I append a '/' to the URL.
This appeared after I removed some unneeded gems from bundler. I also removed the require statement for 'rails/all' in my config file and instead am using selected railties because I don't need a DB/model.
I've checked the answer here but no luck - there doesn't seem to be a missing asset source or href, and the double load also appears in 'incognito' browser mode. I also tested after disabling all extensions on Chrome.
application.rb:
#require 'rails/all' (commented out - active_record & test_unit are not needed)
#------------------------------------------
%w(
action_controller
action_mailer
sprockets
).each do |framework|
begin
require "#{framework}/railtie"
rescue LoadError
end
end
routes.rb:
match '/' => 'pages#home'
match 'root' => 'pages#home'
match '/home' => 'pages#home'
I've also tried:
root => 'pages#home'
root :to => 'pages#home'
home method in pages_controller.rb:
def home
render 'home'
end
Thank you.
Isn't the problem that you are defining the root and /? Defining / shouldn't be needed.
Normally I just define: root :to => 'pages#home'
I'm new to Ruby and Ruby on Rails, am using Ruby 1.9.2 and Rails 3.2.5 on Max OSX Lion, and am working my way through the book "Agile Web Development with Rails (4th Edition)".
I've created their sample depot app using the following commands outlined in Chapter 6:
rails new depot
rails generate scaffold Product title:string description:text image_url:string price:decimal
rake db:migrate
rails server
When I point Safari to "http://localhost:3000/products" I get the following Action Controller: Exception Caught error message instead of seeing a product list page:
Routing Error
No route matches [GET] "/products"
Try running rake routes for more information on available routes.
Running "rake routes" in Terminal gives me:
products GET /products(.:format) products#index
POST /products(.:format) products#create
new_product GET /products/new(.:format) products#new
edit_product GET /products/:id/edit(.:format) products#edit
product GET /products/:id(.:format) products#show
PUT /products/:id(.:format) products#update
DELETE /products/:id(.:format) products#destroy
The following line was automatically added to routes.rb.
resources: product
There is also an index method in products_controller.rb.
class ProductsController < ApplicationController
# GET /products
# GET /products.json
def index
#products = Product.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: #products }
end
end
A search of the book's errata and forums did not turn up any possible solutions.
Thanks in advance.
Figured it out - I had another instance of the WEBrick server running in another terminal window but it was for a demo application from a previous chapter.
Lesson learned. Make sure you run the local server from the directory of the Rails application you want to test.
I have deleted public/index.html.
Here is my config/routes.rb
Those all I have in that file
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
map.root :controller => "home"
I've also tried using map.root :controller => "home#index"
when I ran rake to check
$ rake routes
(in /var/www/atlantix)
/:controller/:action/:id
/:controller/:action/:id.:format
root / {:controller=>"home", :action=>"index"}
I also have:
app/views/home/index.html.erb
app/controllers/home_controller.rb
My issue:
I am a complete newbie of ROR.
I am using Apache and Ruby 1.8.
When I navigate to the http://localhost/myapp/,
I do not see the new home page I created.
Am I missnig something critical in my setup and configuration.
Please advise & help
Mmmm you seem to mix Rails 2 syntax. In Rails 3 you should write:
root :to => 'home#index'
Note: you should also delete the index.html from the public folder.
More information concerning routing can be found here.
I am a noob in ruby on rails so excuse this question if it is a stupid one :
I've added in my routes.rb the command :
root :to => "pages#home"
a have generated a pages-controller using
rails generate controller pages
in my pages_controller.rb i've defined a function named home :
def home
#text = "da"
end
in the views folder from my app in the newly generated pages folder i've created a file named home.html.erb . in it i've placed the following command :
<%= #text %>
The problem is that when i start the server my app isn't rooted in home and even when i run
localhost:3000/pages/home it still doesn't work :
No route matches "/home"
You have created a controller but no view, try these commands
$ rails new myapp
$ cd myapp
$ rails g controller pages index <- this will create a controller **plus** an index view
$ rm public/index.html
now edit routes.rb and add root :to => "pages#index
$ rails s
open http://localhost:3000 and you'll see the new page.
I'm a noob too (I started coding in ruby 2 weeks ago)... I strongly suggest you to get a book, such as Agile Web Development with Rails 4th ed. I covered the book in a week and it gave me a LOT of insight about ruby and rails.
I updated my system to opensuse 11.4 and set up Ruby 1.9.2 via RVM. I reinstalled all the gems and updated bundle all without issue.
The problem is the vague error I get when running the app:
ActionController::RoutingError (undefined method `sub' for nil:NilClass):
app/controllers/application_controller.rb:1:in `<top (required)>'
app/controllers/news_controller.rb:1:in `<top (required)>'
I don't even know where to start looking for the problem. Both files on line 1 is the class declaration. ie class NewsController < ApplicationController and class ApplicationController < ActionController::Base. Neither files have a method call to 'sub' and no other information is given.
The app worked perfectly before the upgrade (which was using Rails 3.0.5 also) so I think the issue is somewhere in Rails, except running a new application with a simple scaffold has no problems. news#index is root in the routes file, but changing root to something else does nothing.
EDIT:
resources :categories,:addresses,:calendars,:topics,:profile,:news,:account_setting
resources :boards do
member do
get :move
post :move_category
end
end
get "user/index"
get 'login/index'
get 'login/new'
post 'login/create'
post 'login/authenticate'
get 'login/forgot_password'
put 'login/reset_password'
root :to => "news#index"
No need to do all that. I think the solution was probably a lot simpler. I just got the same error. Turns out I just had a misnamed helper module:
module AssetHelper
...
end
Should've been
module AssetsHelper
...
end
I got it resolved, although I don't know what caused it.
I created a new app and copied over app, routes, db, lib, and public and the problem disappeared.