Home > Web Front-end > JS Tutorial > Rails: passing data to the browser with

Rails: passing data to the browser with

Mary-Kate Olsen
Release: 2025-01-06 21:02:43
Original
536 people have browsed it

Rails: passing data to the browser with <meta>" />

I'll be posting code snippets like this -- solutions to little problems that I come across in everyday work.

This one is one of the simplest ways to share some structured data with the front end using content_for helper and meta element.

# .erb

<% content_for :head do %>
  <meta name="project-prices" content=<%=prices.to_json%> />
<% end %>
Copy after login
// .js

const meta = document.querySelector('[name="project-prices"]')
JSON.parse(meta.content)

Copy after login

The above is the detailed content of Rails: passing data to the browser with . For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template