Is it possible to reference welcome#index, in the routes file?

Is it possible to reference welcome#index, in the routes file?

e.g. suppose you create a rails program,

so then you do ralsi server you get the welcome page come up.

but the routes file is blank. The welcome controller hasn’t been referenced explicitly.

i’d like to reference it explicitly.

Say I make a make a controller, add an action, and a view, and add a route for that controller. Now I get no welcome page (That ‘yay’ page rails shows).

But suppose I want it to be that when the user goes to /abc, it shows that page.

How can I do that, referencing the welcome controller explicitly? Is it possible?

You can reference any controller/action in the routes. Welcome#index
is no different to any other. Reference it exactly the same way as
you would reference any controller#action.

Also are you sure the routes file was empty initially? Was there not
a 'root:' element?

Colin

You can reference any controller/action in the routes. Welcome#index

is no different to any other. Reference it exactly the same way as

you would reference any controller#action.

Would be all lowercase. (as with all controllers , they have an uppercase letter in some parts of rails, but in the config/routes.rb file they are all lowercase)

I have tried get ‘/abc’, to:‘welcome#index’

or

root ‘welcome#index’

And doesn’t work.

I get uninitialized constant WelcomeController

Also are you sure the routes file was empty initially? Was there not

a ‘root:’ element?

no root element there explicitly by default… if you do rails new blah1 it makes a routes file, not completely blank 'cos has Rails.application.routes.draw do followed by some comment, and then end. No routes in there by default.

Have you got a controller called WelcomeController? If not then what
is the name of the controller with method index?

Colin

You can reference any controller/action in the routes. Welcome#index
is no different to any other. Reference it exactly the same way as
you would reference any controller#action.

Would be all lowercase. (as with all controllers , they have an uppercase letter in some parts of rails, but in the config/routes.rb file they are all lowercase)

I have tried get '/abc', to:'welcome#index'

or
  root 'welcome#index'

And doesn't work.

I get uninitialized constant WelcomeController

Have you got a controller called WelcomeController? If not then what
is the name of the controller with method index?

Colin

It is WelcomeController, but it's inside the Rails gem, so it's Rails::WelcomeController:

Started GET "/" for 127.0.0.1 at 2019-03-08 07:53:01 -0500
   (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
  ↳ /Volumes/eddy/Users/waltd/.rvm/gems/ruby-2.4.4/gems/activerecord-5.2.2/lib/active_record/log_subscriber.rb:98
Processing by Rails::WelcomeController#index as HTML

That's the controller you'll need to reference in your route. I am not at all sure how you would do this in the routes syntax, but maybe something like this would work:

get '/foo', to: 'rails/welcome#index'

Experiment with that angle, or read the Rails API to see if there's another syntax you can use. There's something useful in the Rails Guide "Routing from the outside in" that might work:

scope module: 'rails' do
  get '/foo', to: 'welcome#index'
end

Walter

You understand that there’s a controller I’m trying to reference but that’s about it.

I don’t think you’ve understood my question, or the wording of my question, or know what the WelcomeController is.

I don’t mean to sound patronizing and I know you’re trying to help, but you don’t understand. I’m going to break this down as much as I can.

I said in the first sentence “Is it possible to reference welcome#index, in the routes file?”

That means there’s a thing called the WelcomeController , I didn’t create it, otherwise I wouldn’t have said it like that. And ti’s not just a controller that happens to be called that, otherwise again, I wouldn’t have phrased my question as I did.

You don’t seem to be aware of what WelcomeController is.

I even said

“welcome page (That ‘yay’ page rails shows).”

Do you know what I’m referring to now?

If not,

Try creating a blank rails program…

do the commands

$ rails new blah

$ cd blah

$ rails s

Now read what it says in the console

It says WelcomeController

I didn’t make that

You’ll have it on your computer too.

Is my question clear to you now?

Also you were trying to tell me that the routes file has a root in there explicitly by default. No it does not. All you have to do is create a blank rails program and look at the routes file and you’ll see it does not. So I don’t understand why you say that?!

Rails.application.routes.draw do

For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

end

Thanks, that’s brilliant.

...
I don't mean to sound patronizing

Not sure you have succeeded in that.

...
Also you were trying to tell me that the routes file has a root in there explicitly by default.

No I wasn't. I was asking. I have just tried it and mine does have a
root line in there, commented out.
  # root 'welcome#index'

That is with Rails 4.2

Colin

...
I don't mean to sound patronizing

Not sure you have succeeded in that.

...
Also you were trying to tell me that the routes file has a root in there explicitly by default.

No I wasn't. I was asking. I have just tried it and mine does have a
root line in there, commented out.
# root 'welcome#index'

That is with Rails 4.2

Colin

That line seems to have been removed somewhere along the way to 5.1 or 2, can't recall which version my stunt app used. More "cleanliness is next to impossible to debug".

Walter

Ah that makes sense, Thanks!