DSadaka
DSadaka

Reputation: 86

Undefined local variables in Rails 3 partials after upgrade to Ruby 1.9.3

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:

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.

Upvotes: 0

Views: 142

Answers (1)

gvalmon
gvalmon

Reputation: 958

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

Upvotes: 1

Related Questions