简体   繁体   中英

Padrino Tutorial: Can't Modify Frozen String (Runtime Error)

I am following the Padrino tutorial from here:

https://www.padrinorb.com/guides/blog-tutorial

I am copy and pasting the commands but I quickly ran into an error I don't understand:

$ padrino g controller posts get:index get:show
  create  app/controllers/posts.rb
  create  app/views/posts
   apply  tests/shoulda
 /Users/waprin/.rvm/gems/ruby-2.1.0/gems/padrino-gen-0.12.4/lib/padrino-gen/generators/controller.rb:66:in `prepend': can't modify frozen String (RuntimeError)
from /Users/waprin/.rvm/gems/ruby-2.1.0/gems/padrino-gen-0.12.4/lib/padrino-gen/generators/controller.rb:66:in `create_controller'

This might be a bit late, but in case anyone else runs across this error (and because I just worked through the same tutorial) I'll post anyway...

It looks like there's an issue when generating controllers if a test component is specified. In this case you're using shoulda, but the same happens when using rspec and maybe others. It's been reported as a bug: https://github.com/padrino/padrino-framework/issues/1850 and has been fixed, but isn't yet part of a stable release.

One option to fix this would be to change your Gemfile to work with the latest from their github repo. To do this delete your GemFile.lock file, and comment out the line under 'Padrino Stable Gem' in your GemFile:

gem 'padrino', '0.12.4'

then uncomment the line under 'Or Padrino Edge':

gem 'padrino', :github => 'padrino/padrino-framework'

then re-run bundle install.

Of course, you'll no longer be running the stable release, and that may come with other trade-offs.

As a side-note, I believe that the guide on that page is fairly out of date. I also needed to replace:

  get :index do
    @posts = Post.all(:order => 'created_at desc')
    render 'posts/index'
  end

with:

  get :index, :provides => [:html, :rss, :atom] do
    @posts = Post.order('created_at desc')
    render 'posts/index'
  end

in the Post controller as the active record interface has changed since the time that the guide was written.

I was able to sole this problem by simply going to padrino gem path.

For me it was:

/Users/ahmadhassan/.rvm/gems/ruby-2.2.0/gems/padrino-gen-0.12.4/lib/padrino-gen/generators

open controller.rb and change line number 61:

path = @controller

to

path = @controller.dup

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM