# Create Action

{% embed url="<http://127.0.0.1:3000/hello/index>" %}
[http://127.0.0.1:3000/hello](http://127.0.0.1:3000/hello/index)
{% endembed %}

/app/controllers/hello\_controller.rb

```ruby
class HelloController < ApplicationController
    def index
        render plain:"Hello, This 1s Rails sample page!"
    end
end
```

routes.rb

```
Rails.application.routes.draw do
    get "hello/index"
    get "hello", to: 'hello#index'
end
```

<http://127.0.0.1:3000/hello> <- hello/index 省略可

#### 解説

* `get` "`アドレス", to: 'コントローラー#アクション'`
* `to:=`自動的に割り当てるコントローラーやメソッドではなく、実行するアクションメソッドを自分で明示的に指定したい時に設定する。
* `http://localhost:3000/hello` にアクセスしたら、`to: 'hello#index'`を呼び出す
* \= `HelloController` クラスの`index`メソッドを呼び出す

{% embed url="<https://github.com/BoxPistols/dev-rails6-211031/commit/5f2d1cd59756fdcaa84e4003d2f9cbb865fe915d>" %}
set Controller & Routeing
{% endembed %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://atit.gitbook.io/rails/rails-note/hello-rails/create-action.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
