qiita.rb
link_to 'Link name', 'Prefix name+ _path'
・ Automatically creates html (creates href) ・ Mainly use the following three
○text_field ⇨ User-written space ⇨ Describe the content that fits in one line
○text_area ⇨ User-written space ⇨ Describes more detailed content than form_with ○submit ⇨ Processing when the user presses to access another URL, such as a submit button or enter
ruby:qiita.html.erb
<%= form_with model:@question, local:true do |f| %>
<%= f.text_field :name, class: "form-control" %>
<%= f.text_area :content, class: "form-control" %>
<%= f.submit "Send", class: "btn btn-primary" %>
<% end %>
[Explanation] ○form_with model:@question ⇨ The explanation here is complicated, so I will explain in detail below.
○local:true ⇨ Disable asynchronous communication form ⇨ Details are unknown and need to be investigated separately ...
○do |f| ⇨ Store the hashes in @question separately
○f.text_field :name ⇨ Extract and display the value that hits: name from the separated items.
○f.text_area :content ⇨ Extract and display the value that hits: content from the pieces
○ f.submit "submit" ⇨ Display "Send" on the button
The following two things are important here ① Submit is sent by POST method </ font> (2) How many model names does the form (form_with method use page) include? -If there is only one model, specify the URL in the Prefix that contains only model name + s </ font> as a character string. -If there are two or more models, specify the URL in the Prefix that contains only model name 1_model name 2 + s </ font> as a character string. ・ * (Defined as model name 1, model name 2, ..., model name n from the side closer to root of path)
○ Confirm with 2 patterns of examples during the following Routing
Prefix Verb URI Pattern Controller#Action
answers_edit GET /answers/edit(.:format) answers#edit
root GET / questions#index
question_answers GET /questions/:question_id/answers(.:format) answers#index
POST /questions/:question_id/answers(.:format) answers#create
new_question_answer GET /questions/:question_id/answers/new(.:format) answers#new
edit_question_answer GET /questions/:question_id/answers/:id/edit(.:format) answers#edit
question_answer GET /questions/:question_id/answers/:id(.:format) answers#show
PATCH /questions/:question_id/answers/:id(.:format) answers#update
PUT /questions/:question_id/answers/:id(.:format) answers#update
DELETE /questions/:question_id/answers/:id(.:format) answers#destroy
questions GET /questions(.:format) questions#index
POST /questions(.:format) questions#create
new_question GET /questions/new(.:format) questions#new
edit_question GET /questions/:id/edit(.:format) questions#edit
question GET /questions/:id(.:format) questions#show
PATCH /questions/:id(.:format) questions#update
PUT /questions/:id(.:format) questions#update
DELETE /questions/:id(.:format) questions#destroy
answers_edit GET /answers/edit(.:format) answers#edit
root GET / questions#index
question_answers GET /questions/:question_id/answers(.:format) answers#index
POST /questions/:question_id/answers(.:format) answers#create
new_question_answer GET /questions/:question_id/answers/new(.:format) answers#new
edit_question_answer GET /questions/:question_id/answers/:id/edit(.:format) answers#edit
question_answer GET /questions/:question_id/answers/:id(.:format) answers#show
[About ①] -Submit is sent by the POST method -Destination path candidates are narrowed down to POST among Prefixn
Prefix Verb URI Pattern Controller#Action
question_answers POST /questions/:question_id/answers(.:format) answers#create
questions POST /questions(.:format) questions#create
[About ②] ・ Focus on the URL of the page where the form is displayed -Form_with is displayed in the URL of / questinos / new ・ Includes one question -For Prefix, specify the URL for Prefix that contains only model name + s as a character string. ・ Therefore, specify questions
[About ①] ・ Similar to pattern 1, narrow down by POST method
[About ②] ・ Focus on the URL of the page where the form is displayed -Form_with is displayed in the URL of / questions /: questions_id / answers / new ・ There are two models included, question and answer. -For Prefix, specify the URL for Prefix that contains only model name 1_model name 2 + s as a character string. ・ Therefore, specify question_answers
Recommended Posts