Hi,
I have 2 views on which I am running some javascript for a rating:
from first view:
<script>
$(document).on('turbolinks:load', function() {
$('.star-rating').raty({
path: '/assets/',
readOnly: true,
score: function() {
return $(this).attr('data-score');
}
});
});
</script>
and second:
<script>
$(document).on('turbolinks:load', function() {
$('#star-rating').raty({
path: '/assets/',
scoreName: 'review[rating]'
});
});
</script>
now here they work fine as is but, I don't want them in the html so I
have moved them into reviews.coffee
however, now on using browser forward and back buttons more stars are
added every time I move back and forward with the browser(this doesn't
happen if I leave them in the views)
I can't work out how to fix this (I also have the feeling I shouldn't be
using turbolinks:load like this)
If anyone with decent javascript knowledge could point me in the right
direction I'd be grateful..
thanks,
J.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b7192a2c48791e5f8bee26b1e763742c%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.
On 1 July 2016 at 14:52, Scott Le gendre <lists@ruby-forum.com> wrote:
> I have an advertiser model and an experiment model. I've setup the
> associations as follows:
>
> Advertiser has_many :experiments
> Experiment belongs_to :advertisers
>
> The experiments table has a column titled "experiment_type", which can
> either be AOV or Conversion. I am trying to display experiments for the
> particular advertiser by experiment_type.
>
> I can successfully display ALL of the experiments by advertiser with the
> following iteration
>
> <% @advertiser.experiments.each do |experiments| %>
> <td><%= experiments.id %></td>
> <td><%= experiments.name %></td>
> <% end %>
>
> Or I can successfully display all the experiment_type with the following
> iteration
>
> <% @aov.each do |experiments| %>
> <td><%= experiments.id %></td>
> <td><%= experiments.name %></td>
> <% end %>
>
> What I cannot figure out is how to show the experiment_type by
> advertiser.
Something like
@advertiser.experiments.where(experiment_type: "AOV").each do |experiment|
will get you all the AOV experiments (I have assumed that this is
actually a string "AOV").
Note that I have said do |experiment| with singular experiment. This
makes no difference to the way the code works but makes it clear that
this is a single experiment so that experiment.name looks meaningful.
In fact you would be better to write scopes for AOV and Conversion as
then the code will read even better and you would save some typing.
Colin
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvuhUybObRQN%2BD3P4CMFf1JUs0KR-D4RS%2B4TPqfpyTFDQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
On Fri, Jul 1, 2016 at 6:52 AM, Scott Le gendre <lists@ruby-forum.com> wrote:
> I have an advertiser model and an experiment model. I've setup the
> associations as follows:
>
> Advertiser has_many :experiments
> Experiment belongs_to :advertisers
>
> The experiments table has a column titled "experiment_type", which can
> either be AOV or Conversion. I am trying to display experiments for the
> particular advertiser by experiment_type.
It sounds like you wanted to do this:
http://guides.rubyonrails.org/association_basics.html#polymorphic-associations
HTH,
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Consulting Availability : Silicon Valley or remote
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yDhqW08StQ5bk9MSLOXthB1UQ_RXhkDLc7YcET8-5FRXg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.