Problem overwritting a class with rails 2.3

5 views
Skip to first unread message

Alberto Molpeceres

unread,
May 13, 2009, 1:28:20 PM5/13/09
to Pivotal Labs Open Source
Hi,

First, I'm not sure if the term is overwritting, or reloading, or
reopening the class, sorry if I'm wrong.

Andrei (also in this list) and me are trying to migrate tog (http://
www.toghq.com) from rails 2.2.x + desert 0.3.x to rails 2.3 + desert
0.5. We are almost done, but we are hitting a wall we can solve by
ourselves. I'm going to trry to explain the scenario, so you can
understand it properly. We didn't have this problem with the previous
versions (rails 2.2 + desert 0.3.x). It also seems to work as expected
with rails 2.2.x + desert 0.5

1.- We have a plugin that defines the model "user" (user.rb).
2.- Another plugin, defines model "profile" (profile.rb), and
redefines/overwrittes "user.rb" to add a has_one relationships
(has_one :profile).

And this works as expected using Rails 2.2.x. We can use user.profile
anywhere and it works.

The problem comes when, while using Rails 2.3, we try to ovewrite the
model profile.rb in the host app (directly in the app, altough it
could also happen in a third plugin) to add some new features (in
fact, just an empty profile.rb prodeces this error). As soon as we add
a profile.rb to the app, we get an exception while trying to get
user's profile.

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.include?

(the errors refer tothe call: user.profile)

I suppose it has something to do with relationships reloading in rails
2.3, but before going deeper, I suppose you guys has problably faced
this problem and have a fix or workaround for it.

Any ideas?.

Simon Russell

unread,
May 13, 2009, 1:36:58 PM5/13/09
to pivotallab...@googlegroups.com
I'd call it reopening. What's the stack trace?

Alberto Molpeceres

unread,
May 13, 2009, 1:47:40 PM5/13/09
to pivotallab...@googlegroups.com
Thank you Simon for your quick response.

The stack says "nothing", just fails in the view.

ActionView::TemplateError (You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.include?) on line #3 of
vendor/plugins/tog_core/app/views/shared/_header_options.html.erb:
1: <ul>
2: <% if logged_in? -%>
3: <li>Hello <%= current_user.profile.full_name %></li>
4: <li><%= link_to "Account", member_my_account_path -%></li>
5: <li><%= link_to "My Profile",
edit_member_profile_path(current_user.profile) -%></li>
6: <li><%= link_to 'Dashboard', member_dashboard_path -%></li>

vendor/plugins/tog_core/app/views/shared/_header_options.html.erb:3
vendor/plugins/tog_core/app/views/layouts/application.html.erb:49
vendor/plugins/tog_social/app/controllers/profiles_controller.rb:11:in
`index'

Line 13 of profiles_controller is the render call.

al.

Andrei Erdoss

unread,
May 14, 2009, 2:51:52 PM5/14/09
to pivotallab...@googlegroups.com
I have experienced the same problem with Community Engine Edge which also uses Rails 2.3 and desert 0.5.

Given a fresh installation of Community Engine EDGE (Rails 2.3 + desert 0.5), if I
reopen a class (for example user.rb) in my host app, I'm getting an
exception if this class includes a new relationship. I have tested
that this a Rails 2.3 + desert 0.5 problem, since seems to work as
expected with rails 2.2 + desert 0.5. I have checked it also with tog
(http://www.togh.com) that also uses desert and the same problem
arises. Attached is my user.rb and my overwritten template (just to call
the new relationship).  Strack trace below.

What you will see is that the exception comes from listing activities,
I supposed this is caused for ajax or haml or something else I'm not
familiar with, but the problem is still there.

I have tested both systems that use Desert to make sure that it's not an issue particular to one or the other. The conclusion I believe is that Desert 0.5 is not ready for Rails 2.3. Please take a look at this issue and hopefully find a solution. Thanks,

-------

 NoMethodError in Base#footer_content

Showing vendor/plugins/community_
engine/app/views/activities/_activity.html.haml
where line #8 raised:


You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.include?

Extracted source (around line #8):

5:     -if activity.can_be_deleted_by?(current_user)
6:       =link_to_remote image_tag("icons/delete.png", :plugin =>
'community_engine'), :url => activity_path(activity), :method =>
:delete, :html => {:class => 'right'}
7:
8:     =link_to activity.user.login.capitalize,
user_path(activity.user.login_slug)
9:     - if activity.item
10:       - case activity.item_type
11:         - when 'Post'
--
Andrei Erdoss
user.rb
show.html.haml

Andrei Erdoss

unread,
May 15, 2009, 5:05:44 PM5/15/09
to pivotallab...@googlegroups.com
I have found these solutions, here: http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/f54f18f4d4354926?pli=1

Please let me know if it worked for you, too. Thanks,

First, you could put something like this in your plugin’s init.rb file:
# This plugin should be reloaded in development mode.
if RAILS_ENV == ‘development’
ActiveSupport::Dependencies.load_once_paths.reject!{|x| x =~
/^#{Regexp.escape(File.dirname(__FILE__))}/}
end

Second, you could put something like this in your application’s
environment.rb file:
config.reload_plugins = true if RAILS_ENV == ‘development’

--
Andrei Erdoss

Simon Russell

unread,
May 16, 2009, 12:28:56 AM5/16/09
to pivotallab...@googlegroups.com
Glad to see somebody has a solution -- sorry I didn't reply sooner, I
didn't really have much to add :) (not using Rails 2.3)

Seems like something to add to Desert; I wonder how much of Rails 2.3
"engines" support actually just breaks things -- it was my
understanding that the Rails 2.3 stuff doesn't actually mix code, it
just loads files from plugins? (i.e. you can't have Xyz class defined
in two different xyz.rb files) How much does Desert fix that up?
Reply all
Reply to author
Forward
0 new messages