Home>

○ Unclear points
Creating a new submission form.
This form contains a text box for the subject, a text area for the body and submit
There are button controls.
If i enter the subject and body and send it, the process to save it in the DB is included.
For some reason only the subject is not saved.
When new data is created from the console, both the subject and body are saved in the DB.
Will be done.
I don't understand why only the subject is not registered.
Could someone please tell me the cause?

○ Source code

View
new.html.erb
Post a question

<% = form_tag ("/ questions/create", method:: "post") do%>

Subject



Body





<% end%>

Controller (Nothing has been written for other actions yet. Only the device.)

def create
@ question = Question.new (subject: params [: subject],
body: params [: body])
@ question.save
redirect_to ("/ questions/index")
end

○ DB confirmation (partial excerpt)
ID | Subject | Body |
1 | test | test |
2 | subject | body |
3 | subject | body |
4 | subject | body |
5 || From Form |
6 | test | test2 |
7 || Will it work from the form |
8 | test | test2 |

IDs 5 and 7 are creating data from the form.
The subject is not saved in the DB.

○ Environment
AWS Cloud9
rails Rails 5.2.4.4
ruby 2.6.3
SQLite version 3.33.0

  • Answer # 1

    <input type = "text", name = "subject">


    Between type and name of,Is unnecessary. Separate with spaces