small medium large xlarge

Imag0120_1_pragsmall
22 May 2017, 15:50
Patrício João dos Santos (6 posts)

At Iteration F2, Pag 157 we have this code:

$('#cart').html("<%=j render(@cart) %>"); For those who are starting, this code could not work, because new rails does not come with jquery by default. So what you need to do is add jquery.

First add jquery using yarn:

$ bin/yarn add jquery

Then add a require statement at app/javascripts/application.js file:

//= require rails-ujs //= require turbolinks //= require jquery //= require_tree .

Generic-user-small
13 Jun 2017, 20:53
Karen Hoofnagle (1 post)

You need to backout a touch further. People may not have yarn installed at all, in which case they’ll need to visit https://yarnpkg.com/lang/en/docs/install/ for install instructions first.

Generic-user-small
20 Jul 2017, 12:51
John Yeates (8 posts)

Yarn is now installed as part of the installation instructions in chapter 1, so that shouldn’t be a problem.

However, if you add jquery through yarn, it doesn’t seem to load jquery-ui-rails correctly and your application will throw an error on each page load. Adding gem jquery-rails to the Gemfile instead worked for me.

You must be logged in to comment