B
B
bismoney2015-10-23 22:39:00
Ruby on Rails
bismoney, 2015-10-23 22:39:00

Ruby and Rails query to table?

Hi friends!
There is a Post type, a post table in the database. For example, there is a title table body table
. I go to post/new and fill everything in, everything is ok.
Now I needed to create an options table that will include non-basic things like in post, for example, the text field autor "Author".
I want to add the autor field to the post / new view code, but I don’t know how to make it write to the options table and link it to the news by id.
That is, I need something like this when creating a post:

поле title - заголовок > записывается в таблицу post в title
поле body - текс > записывается в таблицу post в body
поле autor - Имя Фамилия -> а вот что бы эта писалась в таблицу options в autor

That is, firstly, I don’t understand how to register this field in form.ekb so that when creating a post, she writes exactly in options in the field I need. Secondly, it is not clear how it will be linked to the news in the post table. I understand it will be something like creating an id:id News entry in options, which will be the same as in post.
Thirdly, I can't figure out how to register this field in edit.ekb, so that when editing a news article, it would check for the presence of an already registered author by the news id and allow him to change and write a new value.
Fourth, for example, there was only the autor field, but, for example, test1 was also needed as a text field. How to do, for example, if I go to the news where the author is already registered, and therefore a record is created in the option with the id of the news, how to make it so that when writing in an already existing news in the test field, he does not create a new record, but enters it into an existing one .
Immediately forgive me for the dinnopost, crooked Russian, and nubism ... Explain to whom it is not difficult ... Thank you very much and human in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)

I understand that you want to associate the Post model with the Option model as Post has_one :option
read here rusrails.ru/active-record-associations

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question