small medium large xlarge

Generic-user-small
15 Apr 2009, 20:36
Dennis Keith (13 posts)

I am working my way slowly through AWDR3 following the examples in the book and am having some problems. For instance, when I downloaded the products.html.erb, I get the following error: undefined method -' for {:length=>80}:Hash < undefined method -‘ for {:length=>80}:Hash

Extracted source (around line #15):

12: <td class="list-description"> 13: <dl> 14: <dt><%=h product.title %></dt> 15: <dd><%=h truncate(product.description.gsub(/<.*?>/,’’), :length => 80) %></dd> 16: </dl> 17: </td> 18: >

Is there some component of Ruby that I have not loaded? I’m running on Widows XP.

Thanks

Dennis Keith

Samr_small_pragsmall
15 Apr 2009, 23:08
Sam Ruby (634 posts)

See footnote on page 93 of the PDF or page 85 of the printed book: best bet is to upgrade to Rails 2.2.2 or later, but you can proceed further with Rails 2.0 (or even 2.1) by removing the “:length => “ from the call to truncate. Other parts of the book (like the chapter on I18N) won’t work at all with versions prior to 2.2.

Generic-user-small
16 Apr 2009, 05:58
Dennis Keith (13 posts)

Sam,

Thanks for your response. I have executed both commands:

gem update –system gem update rails

and am still getting the same error.

Rails -v returns 2.3.2. Ruby -v returns 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] gem -v returns 1.3.2

I am running on Win XP Pro SP 3.

I have shut down Instant Rails as well as the WEBrick server and restarted with no change in the error. Removing the reference to :length => works but leaves me very uneasy since there is something here that may well be needed later and I don’t know why it doesn’t work.

Any assistance would be greatly appreciated.

Thanks

Dennis Keith

Samr_small_pragsmall
16 Apr 2009, 11:52
Sam Ruby (634 posts)

It looks like you now have the right version of Rails on your system, and acceptable versions of ruby and gem, but it still looks like your application is using a previous version of Rails. You can tell for sure by typing @ruby script/console@, and it will respond with something like:

Loading development environment (Rails 2.3.2)

</code>

If you get anything different, take a look at @config/environment.rb@, there you will find a line which starts with @RAILS_GEM_VERSION@. If it doesn’t already say so, change the value you find there to @2.3.2@. Finally, execute @rake rails:update@

At this point, you should be running Rails 2.3.2, @ruby script/console@ should confirm it, and including @:length =>@ on the truncate call will work (if I remember correctly, doing otherwise will also work, but will produce messages complaining about such usage in your log file).

Since you will now be running 2.3.2, be sure to check the “changes”:http://pragprog.wikidot.com/changes-in-rails-2-3 page for things that might affect you.

Generic-user-small
16 Apr 2009, 12:50
Dennis Keith (13 posts)

Sam,

Thanks for your assistance. The ruby script/console response indicated that I was running 2.0.2 so I changed the RAILS_GEM_VERSION in the …Depot\Config directory to 2.3.2, saved and exicuted rake rails:update which returned with no response. I then went to confirm with ruby script console and got the following response:

C:\InstantRails\rails_apps\work\depot>ruby script/console Loading development environment (Rails 2.3.2) C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:580:i n send':NoMethodError: undefined method cache_template_extensions=’ for Action View::Base:Class » at which point the batch program hung and required an exit for the console to resume. Unfortunately, the program still has the same error.

There must be something I am still missing.

Thanks

Dennis Keith

Samr_small_pragsmall
16 Apr 2009, 16:36
Sam Ruby (634 posts)

It “looks like”:http://www.ruby-forum.com/topic/152909 @cache_template_extensions@ was removed. You can safely remove this line.

In an ideal world, Rails 2.3.2 would be backwards compatible. Failing that, in an ideal world @rake rails:update@ would have made this change for you. Neither appear to be the case in this situation, which is unfortunate. Fortunately, the fix is easy (find and remove the line).

Taking a step back, and given that your goal at the moment is more to learn Rails and less to debug Rails version compatibility issues, one alternative you might want to consider is renaming the depot directory (and thereby giving yourself a place to refer to and possibly switch back to) and starting over.

Generic-user-small
16 Apr 2009, 16:55
Dennis Keith (13 posts)

Thanks for the response. I had just found a reference to the two lines in Action_View\base.rb. The first thing that was interesting was that they occurred in the actionpack-2.0.2 tree but not in the actionpack-2.3.2 one. In any case, I commented out the two lines, saved the file, and tried the Products page again - with the same failure. I ran rake rails:update again and then tried the script/console with the same error as before. Knowing now that the depreciated cache_template_extensions was not in the base class of the action_view (2.3.2) the error message now seems to indicate that something in the ruby script/console seems to be calling it.

Sorry I am so persistent - my curse.

Dennis Keith

Samr_small_pragsmall
16 Apr 2009, 17:49
Sam Ruby (634 posts)

Eek! I wasn’t suggesting that you modify Rails itself. Sorry for being unclear.

If you generate a project (e.g. @rails depot@) using version 2.0.2, you will find the following line in @config/environments/development.rb@:

config.action_view.cache_template_extensions         = false

That line is no longer necessary in Rails 2.3.2, nor would it be generated if you created a new project afresh. And, yes, @ruby script/console@ will load your development environment. So the fix is to remove this line from your project.

P.S. There is a similar line in @config/environments/production.rb@.

Generic-user-small
16 Apr 2009, 18:54
Dennis Keith (13 posts)

Thanks Sam. I took both directions. I commented out the lines referencing the depreciated method throughout and got the app to work. Then, to clean things up a bit, I took your suggestionm and renamed the depot application and restarted. This also worked. Back on track.

Thanks again for the help

Dennis Keith

You must be logged in to comment