0

I know there are several posts on this issue but none of the solutions I've read help here.

I've just upgraded from Ruby 1.8.7 to 1.9.3p429 and now, I get undefined local variable in my partials.

I am calling a partial (from a partial in case that's relevant) thusly:

= render :partial => 'user_name', :locals => {:user => item_user, :extra_class => "active"}

In the partial, I access these locals thusly:

- if(current_user and user.silhouette_user_id.to_i == current_user.silhouette_user_id)
    = notranslate(current_user.full_name)
- else
    - if !local_assigns[:extra_class].nil?
        = notranslate(link_to( h(user.full_name), stream_url(:user_id => user.silhouette_user_id), :class => extra_class )) rescue "Anonymous"
    - else 
        = notranslate(link_to( h(user.full_name), stream_url(:user_id => user.silhouette_user_id) )) rescue "Anonymous"
    = notranslate(link_to "Pro", "#", :class => "badge badge-pro", :title => "#{user.part_name} is pro") if SSO.is_pro? user

I can access the locals via the local_assigns hash, so if I add these lines to the top, I have access:

  • user = local_assigns[:user]
  • extra_class = local_assigns[:extra_class]

I could live with that. However, it gets worse. user is an ActiveRecord model object. I cannot, however, access the attributes of this object with user.attribute notation. Instead I have to user user[:attribute].

I could still get by with this except that some of the attributes of user are actually methods, which I cannot access using user[:method].

I thought it might be the Rails, which was at 3.1.12 so I upgraded to 3.2.13 with no change.

Any ideas? Could it be the HAML processor? All other posts that were solved used ERB.

Ryan Gates
  • 4,501
  • 6
  • 50
  • 90
DSadaka
  • 76
  • 6

1 Answers1

1

Try using this way for rendering partials (it's correct way for Rails 3):

= render 'user_name', user: item_user, extra_class: "active"

And access to objects using user and extra_class

gvalmon
  • 938
  • 5
  • 18
  • Noone else having this issue? – DSadaka Jul 26 '13 at 13:26
  • I solved this issue. It was caused by my custom define_new_methods on the user. c.f. http://stackoverflow.com/questions/17941607/devise-current-user-weird-behavior-after-upgrade-to-ruby-1-9-3/17985434#17985434 – DSadaka Aug 01 '13 at 05:24