Answer the question
In order to leave comments, you need to log in
How to update a field in the database on RoR by clicking on a link?
Just started to poke to learn Ruby and RoR. In the index view, where all the data from the database table is displayed, I want to add a link to update one of the fields.
<tbody>
<% @my_table.each do |my_table| %>
<tr>
<!-- -->
<td><%= link_to 'Тут ссылка, которая должна обновить одно из полей в БД у текущей записи', ............, method: :patch, data: {confirm: 'Вы уверены?'} %>
</tr>
<% end %>
</tbody>
Answer the question
In order to leave comments, you need to log in
Well look. Most likely you have an update action for my_table. It says something like
let's write in full for clarity:
@my_table.update_params(params.require(:my_table).permit(:my_field, :my_field2)
link_to "Nonsense search", searches_path(foo: "bar", baz: "quux")
# => <a href="/searches?foo=bar&baz=quux">Nonsense search</a>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question