DEV Community

n350071πŸ‡―πŸ‡΅
n350071πŸ‡―πŸ‡΅

Posted on

Pass data from Rails to JS

From Rails

<%= link_to(
  'likeπŸ‘',
  '#',
  id: 'like',
  data: {
    userId: current_user.id
  }) 
%>

To JS

$('#like').click(function(event){
 console.log(event.target.dataset.userId)
})

πŸ”— Parent Note

Top comments (2)

Collapse
 
vegann profile image
Damian Kaczmarczyk • Edited

Nice post! But You mistyped "dataset" 😁

Collapse
 
n350071 profile image
n350071πŸ‡―πŸ‡΅

Thank you! I fixed it πŸ‘