Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sinatra - undefined method `join' for #<String> - after removing Gemfile.lock

Tags:

ruby

sinatra

I tried to update the Ruby version of a Sinatra website I am working on to 2.1.3. When I tried to bundle I had some errors. Then I removed the Gemfile.lock and bundle install proceeded. But when I ran the website I noticed some thing like

NoMethodError at /auth/login
undefined method `join' for #<String:0x000000062d3830>

My observations are as below.

  • Downgraded to Ruby 2.1.2 - problem preserved
  • Checked out the project as it was before (Ruby 2.1.2 with the old Gemfile.lock) worked
  • The error showed up with a yield_content(:head) tag.
    • Removed all yield_content tags
    • Error showed up rendering the slim file for the page - slim :index, :layout => :layout, :locals => body_locals

What could be the error? I created a diff off the state of the Gemfile.lock before and after: https://gist.github.com/ziyan-junaideen/fb903abbdafdc2d4a02f

Error output from the terminal: https://gist.github.com/ziyan-junaideen/54bff4f05a5a7beeedff

I thought it was some SLIM error and downgraded Slim to 2.0.3 which used to be before the bundle install, but had no luck.

Any suggestion is highly appreciated.

Thanks

like image 594
Ziyan Junaideen Avatar asked Feb 02 '26 22:02

Ziyan Junaideen


2 Answers

I have solved it by reinstalling slim and temple in versions slim: 2.0.3 and temple: 0.6.8, it's probably in temple, 'cos downgrading slim is not enough

like image 199
vaclavt Avatar answered Feb 04 '26 14:02

vaclavt


I've got this error as well.

After some research I've found that it is happening because 'output buffer' for template rendering is an instance variable (its default name is @_out_buf), thus it is overwritten when each (sub)template rendering completes (because partials are being rendered in the same scope as main template)

There are a few ways to fix this without downgrading sinatra/slim/temple:

  • Make default outvar value equals to _out_buf (local variable) @ lib/sinatra/base.rb#L814
  • Pass an outvar option to slim method like this: == slim :sub_template, outvar: '_out_buf'

I've also opened an issue at sinatra's repo at github: https://github.com/sinatra/sinatra/issues/939 (let's see what authors will say about this)

like image 21
kallax Avatar answered Feb 04 '26 15:02

kallax



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!