R
R
Roman Volkov2015-01-06 16:49:24
Ruby on Rails
Roman Volkov, 2015-01-06 16:49:24

How to write information to the ruby ​​on rails database when clicking on a link?

How, when clicking on a link, take information from two passed variables and write it to the database?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Q
Quickerz, 2015-01-06
@white_wolf_17

Option one. You can write link_to with additional parameters
When clicked, a call will be made to the method that has the corresponding method and name, plus there will be two variables in the params hash: variable1 and variable2.
Option two. Use javascript. In the simplest version, you can use jQuery

$.ajax({
    url: 'target_url',
    method: 'PUT',
    data: {variable1: value1, variable2: value2}
})

You can use ready-made solutions for a similar task if it is too often repeated and has options. Here it is for example.

A
Alexey P, 2015-01-06
@ruddy22

can it be like this

<%= link_to my_controller_path(@model, variable: value1, variable2: value2), method: :put, remote: true%>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question