Ruby on Rails
Friday, March 8, 2019
On Friday, 8 March 2019 13:02:46 UTC, Walter Lee Davis wrote:
> On Mar 8, 2019, at 7:40 AM, Colin Law <cla...@gmail.com> wrote:
>
> 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
>
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
Thanks, that's brilliant.
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3e4d82f0-44b9-4627-98c8-41ade8b6dcf2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment