A
A
Andrey Korablin2016-02-04 11:24:40
JavaScript
Andrey Korablin, 2016-02-04 11:24:40

How to display all users who liked the order?

For likes, the acts_as_votable gem is used ( https://github.com/ryanto/acts_as_votable).
For output, use the query <%= @booking.votes_for.voters.each do |v| %><% end %>.
But both in the browser and in the rails console, the request to the order displays square brackets [].

[26] pry(main)> book.votes_for
=> []

And this is the output when someone liked it:
[27] pry(main)> book.votes_for.voters
ActsAsVotable::Vote Load (9.5ms) SELECT votes.* FROM votes WHERE votes.votable_id = 35 AND votes.votable_type = 'Booking'
User Load (2.0ms) SELECT users.* FROM users WHERE users.id IN (51)
=> [# id: 51, 
email: "[email protected]", 
encrypted_password: "$2a$10$BWOeIRguEHIzkUj0Cx/QfOdhMu.QbRLlkZx7sBaTPEhGtCerehSfy",
reset_password_token: nil, 
reset_password_sent_at: nil,
remember_created_at: nil, 
sign_in_count: 6,
current_sign_in_at: Sat, 09 Jan 2016 01:28:27 UTC +00:00,
last_sign_in_at: Fri, 08 Jan 2016 20:54:28 UTC +00:00, 
current_sign_in_ip: "127.0.0.1",
last_sign_in_ip: "127.0.0.1", 
created_at: Thu, 03 Dec 2015 10:11:03 UTC +00:00, 
updated_at: Sat, 09 Jan 2016 01:28:27 UTC +00:00, 
name: "Буба", 
confirmation_token: "nkiXZeja8MB_KycryxpA",  
confirmed_at: Thu, 03 Dec 2015 10:12:11 UTC +00:00, 
confirmation_sent_at: Thu, 03 Dec 2015 10:11:03 UTC +00:00,
unconfirmed_email: nil, 
avatar_file_name: "N9WpwqK.jpg", 
avatar_content_type: "image/jpeg", 
avatar_file_size: 126608, 
avatar_updated_at: Sat, 09 Jan 2016 01:21:58 UTC +00:00, 
balance: nil, surname: "Хуга", 
is_female: false, 
banned: false, 
birthday: Mon, 09 Jan 1950, 
votes_count: nil, 
rating_id: nil, 
category_id: 1, 
subcategory_id: 2, 
cities_id: nil, 
city_id: 3, 
country_id: 2, 
karma: 0, 
phone: nil, 
role: "Клиент", 
phone_number_id: nil>]

Who faced such glitches?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Dyachuk, 2016-02-05
@Renius

1) The documentation does not say that `fotes_for` should output something other than square brackets, which are called an empty array 2) as far as I can see, ` fotes_for`
can be either an intermediate scope or any other entity that returns anything
, I do not see any unexpected behavior here, since the expected behavior is described in the documentation poorly, or glitches.
And it's not entirely clear to me, you write:
then write what book.votes_for => []
and then write what book.votes_for.voters => коллекция юзеров
In your examples, you apply different chains of methods to different objects and get different results - quite expected.
What behavior did you expect?

A
Atom777, 2016-02-04
@Atom777

As easy as pie. Just put the order button link not directly, but through a redirect (an additional page). Those. in add. page put a redirect with a hit counter. You can easily find the redirect code itself, it is very small and, I don’t remember exactly, options like 5 or 6. There are really a lot of options, at least in html, at least in php or in javascript. Good luck.

A
Andrey Korablin, 2016-02-17
@monaxide

Found the problem - Why are extra lines in the form when using the .each method?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question