Post History
#3: Post edited
- The function `comment_thread_path` is created automatically by Rails, based on the information provided in `config/routes.rb`.
See [The Ruby on Rails guide to routing](https://guides.rubyonrails.org/routing.html) for further details.- Specifically, line 236 of `config/routes.rb` says (enclosing scope included for context):
- ```ruby
- scope 'comments' do
- ...
- get 'thread/:id', to: 'comments#thread', as: :comment_thread
- ...
- end
- ```
This responds to a GET request on the route `/comments/thread/:id` by calling the `thread` method of the `CommentsController` (signified by `comments#thread`).The `as: comment_thread` overrides the default name that Rails would otherwise use in its automatically generated helper functions (otherwise it would use the default `comments_thread` - note the pluralisation). Now `comment_thread_path` and `comment_thread_url` are available, each a function taking a thread id as argument:- - Calling `comment_thread_path(123)` returns `/comments/thread/123`
- - Calling `comment_thread_url(123)` returns the same thing but including the domain at the beginning, such as `example.com/comments/thread/123`.
- The function `comment_thread_path` is created automatically by Rails, based on the information provided in `config/routes.rb`.
- See [Rails Routing from the Outside In](https://guides.rubyonrails.org/routing.html) for further details.
- Specifically, line 236 of `config/routes.rb` says (enclosing scope included for context):
- ```ruby
- scope 'comments' do
- ...
- get 'thread/:id', to: 'comments#thread', as: :comment_thread
- ...
- end
- ```
- This responds to a GET request on the route `/comments/thread/:id` by:
- - First calling the `thread` method of the `CommentsController`
- - Then rendering the `app/views/comments/thread.html.erb` view.
- See [Action Controller Overview](https://guides.rubyonrails.org/action_controller_overview.html) for further details.
- The `comments#thread` in the routes file determines both:
- - Which controller and method to call (being in the format `controller#method`)
- - Which view to render and where to find it (being in the format `directory#viewfile`)
- The optional `as: comment_thread` overrides the default name that Rails would otherwise use in its automatically generated helper functions (otherwise it would use the default `comments_thread` - note the pluralisation). Now `comment_thread_path` and `comment_thread_url` are available, each a function taking a thread id as argument:
- - Calling `comment_thread_path(123)` returns `/comments/thread/123`
- - Calling `comment_thread_url(123)` returns the same thing but including the domain at the beginning, such as `example.com/comments/thread/123`.
#2: Post edited
- The function `comment_thread_path` is created automatically by Rails, based on the information provided in `config/routes.rb`.
- See [The Ruby on Rails guide to routing](https://guides.rubyonrails.org/routing.html) for further details.
- Specifically, line 236 of `config/routes.rb` says (enclosing scope included for context):
- ```ruby
- scope 'comments' do
- ...
- get 'thread/:id', to: 'comments#thread', as: :comment_thread
- ...
- end
- ```
- This responds to a GET request on the route `/comments/thread/:id` by calling the `thread` method of the `CommentsController` (signified by `comments#thread`).
The `as: comment_thread` overrides the default name that Rails would otherwise use in its automatically generated helper functions (otherwise it would use the default `comments_thread` - note the pluralisation). Now `comment_thread_path` and `comment_thread_url` are available, each a function taking a thread id as argument.Calling `comment_thread_path(123)` returns `/comments/thread/123`, and calling `comment_thread_url(123)` returns the same thing but including the domain at the beginning, such as `example.com/comments/thread/123`.
- The function `comment_thread_path` is created automatically by Rails, based on the information provided in `config/routes.rb`.
- See [The Ruby on Rails guide to routing](https://guides.rubyonrails.org/routing.html) for further details.
- Specifically, line 236 of `config/routes.rb` says (enclosing scope included for context):
- ```ruby
- scope 'comments' do
- ...
- get 'thread/:id', to: 'comments#thread', as: :comment_thread
- ...
- end
- ```
- This responds to a GET request on the route `/comments/thread/:id` by calling the `thread` method of the `CommentsController` (signified by `comments#thread`).
- The `as: comment_thread` overrides the default name that Rails would otherwise use in its automatically generated helper functions (otherwise it would use the default `comments_thread` - note the pluralisation). Now `comment_thread_path` and `comment_thread_url` are available, each a function taking a thread id as argument:
- - Calling `comment_thread_path(123)` returns `/comments/thread/123`
- - Calling `comment_thread_url(123)` returns the same thing but including the domain at the beginning, such as `example.com/comments/thread/123`.
#1: Initial revision
The function `comment_thread_path` is created automatically by Rails, based on the information provided in `config/routes.rb`. See [The Ruby on Rails guide to routing](https://guides.rubyonrails.org/routing.html) for further details. Specifically, line 236 of `config/routes.rb` says (enclosing scope included for context): ```ruby scope 'comments' do ... get 'thread/:id', to: 'comments#thread', as: :comment_thread ... end ``` This responds to a GET request on the route `/comments/thread/:id` by calling the `thread` method of the `CommentsController` (signified by `comments#thread`). The `as: comment_thread` overrides the default name that Rails would otherwise use in its automatically generated helper functions (otherwise it would use the default `comments_thread` - note the pluralisation). Now `comment_thread_path` and `comment_thread_url` are available, each a function taking a thread id as argument. Calling `comment_thread_path(123)` returns `/comments/thread/123`, and calling `comment_thread_url(123)` returns the same thing but including the domain at the beginning, such as `example.com/comments/thread/123`.