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

103 views
Skip to first unread message

Robert Phillips

unread,
Mar 8, 2019, 11:46:33 AM3/8/19
to Ruby on Rails: Talk
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?


Colin Law

unread,
Mar 8, 2019, 12:07:16 PM3/8/19
to Ruby on Rails: Talk
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

Robert Phillips

unread,
Mar 8, 2019, 12:19:46 PM3/8/19
to Ruby on Rails: Talk


On Friday, 8 March 2019 12:07:16 UTC, Colin Law wrote:

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.


Colin Law

unread,
Mar 8, 2019, 12:41:34 PM3/8/19
to Ruby on Rails: Talk
On Fri, 8 Mar 2019 at 12:19, Robert Phillips
<robert.p...@gmail.com> wrote:
>
>
>
> On Friday, 8 March 2019 12:07:16 UTC, Colin Law wrote:
>>
>>
>> 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

Walter Lee Davis

unread,
Mar 8, 2019, 1:02:46 PM3/8/19
to rubyonra...@googlegroups.com
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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLv4JqvtXmHCDOuLCWo23DOP0o68CPDuB6eaLzkX-kk6eg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Robert Phillips

unread,
Mar 8, 2019, 1:05:04 PM3/8/19
to Ruby on Rails: Talk


On Friday, 8 March 2019 12:41:34 UTC, Colin Law wrote:


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

Colin

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


Robert Phillips

unread,
Mar 8, 2019, 1:11:17 PM3/8/19
to Ruby on Rails: Talk
Thanks, that's brilliant. 
 

Colin Law

unread,
Mar 8, 2019, 2:19:01 PM3/8/19
to Ruby on Rails: Talk
On Fri, 8 Mar 2019 at 13:05, Robert Phillips
<robert.p...@gmail.com> wrote:
> ...
> 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

Walter Lee Davis

unread,
Mar 8, 2019, 2:22:18 PM3/8/19
to rubyonra...@googlegroups.com
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

>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLv%2BB0ZXKyA7-whJQQcWyysA-kTWoWtrjaCKhrUhOssrUw%40mail.gmail.com.

Robert Phillips

unread,
Mar 8, 2019, 8:21:18 PM3/8/19
to Ruby on Rails: Talk
Ah that makes sense, Thanks! 
Reply all
Reply to author
Forward
0 new messages