#1007 ✓resolved
Arnaud D.

Tag <a action="new"> adds new elements in collection

Reported by Arnaud D. | May 21st, 2012 @ 09:33 PM

Hi,

In latest hobo 1.4 with rails 3.1.4, I discover a little problem, not sure really linked to Hobo or new Rails behavior, but, in tag , line 117 of file hobo_rapid/taglibs/html/a.dryml, we use

new_record = target.new
where target is
target = to || this

But, it appears that when using target.new (that is similar to this.new where this is a collection), a new member is also created within the collection Array.

For example, I see in rails console :

>> u=User.first
  User Load (0.7ms)  SELECT users.* FROM users LIMIT 1
#<User ...>
>> u.roles
u.roles
  Role Load (0.8ms)  SELECT roles.* FROM roles INNER JOIN entity_roles ON roles.id = entity_roles.role_id WHERE entity_roles.entity_id = 1 AND entity_roles.entity_type = 'User'
[#<Role id: 2, name: "Administrator", description: "Admin", created_at: "2012-04-25 04:21:56", updated_at: "2012-04-25 04:21:56">]
>> r=u.roles
[#<RaliRole id: 2, name: "Administrator", description: "Admin", created_at: "2012-04-25 04:21:56", updated_at: "2012-04-25 04:21:56">]
>> r.size
1
>> r.class
Array
>> target=r
[#<RaliRole id: 2, name: "Administrator", description: "Admin", created_at: "2012-04-25 04:21:56", updated_at: "2012-04-25 04:21:56">]
>> new_record=target.new
new_record=target.new
#<RaliRole id: nil, name: nil, description: nil, created_at: nil, updated_at: nil>
>> r.size
2

As you can see, the original Array r has been incremented of one empty member.

I would suggest this correction :
Line 117

new_record = target.new
becomes
target.member_class.new

But since I'm not entirely sure that we will have an Array at this place, it could be also something like this :

new_record = (target.class==Array) ? target.member_class.new : target.new

Best regards,
Arnaud.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Pages