Home > Blockchain >  Invalid yield, SyntaxError in Ruby
Invalid yield, SyntaxError in Ruby

Time:11-20

I am absolutely NOT a developer, but I am trying to get this abandoned app to work

This is the code in a file called layout.erb which is HTML

<div >
<%= yield %>
</div>

It's throwing this error:

SyntaxError - /wallop/app/views/layout.erb:53: Invalid yield:

I understand that they're using Bootstrap and that "yield" is a special term in Ruby and the %'s are supposed to print and evaluate the code -- I get all that, I just don't see why it's erroring.

This app was written a long time ago and abandoned, the devs moved on and made a commercial version of it, so they are not interested in helping update the old source, I am more or less interested in tinkering with it so that I can teach myself Docker and some other things.

I have not tried anything, just researched the error

I think this may have something to do with the fact that this is an old app and it was written in Ruby 2 and I'm running Ruby 3, but that is just a guess.

UPDATE:

This is exactly the same problem, the app is also using Sinatra / Thin:

https://github.com/mocdaniel/dashing-icinga2/issues/121

They fixed it by reverting to an older Ruby version, however I’m not sure I’ll be able to do that easily

I’m using alpine:latest and then running apk add ruby-json ruby-dev and ruby-bundler from the repo, it’s grabbing the latest versions…I don’t know alpine or Docker well enough to specify how to grab the older versions and I would prefer not to compile & install them manually.

It may actually be easier to just fix the code to work with Ruby 3.

CodePudding user response:

First of all, yes, if the application was written in Ruby 2.x you should try to set it up using the same Ruby version.

Without more context it's hard to say what's the root cause of the problem. Maybe you have multiple unnamed yield statements in the layout? You can read more about layouts and rendering in the documentation - https://guides.rubyonrails.org/layouts_and_rendering.html#understanding-yield

CodePudding user response:

I figured it out. The problem as I suspected was related to Ruby 3.x breaking the app. Since I am not a dev, the easiest workaround is to not use Ruby 3.x.

The app uses gems like Thin and Sinatra, and they are broken with Ruby 3.x for some reason.

I was able to search the alpine repo website, and discovered that using a Docker base image of FROM alpine:3.14 pulls Ruby 2.7.6 packages (rather than alpine:latest, which pulls Ruby 3.x packages), which fixes the problem.

  • Related