B
B
bismoney2015-10-24 02:27:53
Ruby on Rails
bismoney, 2015-10-24 02:27:53

Field from another table?

All good!
How to display in the post _form.html.erb view a
Text field from another table?
For example from options.
For example, sorting like this
<%= f.collection_select :category_id, Category.order(:name), :id, :name %>
In this case, it takes from the categories table and lists it.
How to do something similar but just for a text field? So that it can be edited and saved to the database but already in the options table, for example.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bismoney, 2015-10-24
@bismoney

Issue resolved.
Thanks to the user Toaster
Dmitry Sharikov Dmitry Sharikov
Who quickly told everything ... Many thanks to him.

R
Roman Mirilaczvili, 2015-10-24
@2ord

The train of thought for solving the problem could be as follows:
By what means is the data entered into the database tables using the RoR framework?
Through model instances and create/update_attributes/destroy/delete methods.
Which controller method will be responsible for updating?
Method according to REST and CRUD concepts.
How is the data coming into the controller method?
All data is received via HTTP GET/POST/PUT/PATCH/DELETE requests through parameters that are available in params.
How can I pass data through parameters?
Can be sent to:

  • submitting the form parameters of the model instance. In this case, you can send both parameters from form elements, and in hidden parameters.
    Read:
    https://mkdev.me/posts/kak-rails-peredayot-paramet...
    https://mkdev.me/posts/vsyo-chto-nuzhno-znat-o-rou...
    How to pass "non-native" attributes from a model instance form?
    Through parameters in another model's namespace. Schematically like this:
    form
      modelA
        paramK
        paramL
        paramM
      modelB
        paramX
        paramY
        paramZ

    Will you figure it out on your own?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question