Hi all
I have a relation @user.tracks,
track(user_id:integer, point:integer, track_name:string)
I want to reorganizing all user's track.point from integer to range.
Another words,
from
array = [1,4,10,14,22]
do
array = [0..1, 2..4, 5..10, 11..14, 15..22]
My code is:
@points = @user.tracks.pluck(:point).unshift(-1)
@ranges = @points.each_cons(2).map{|a,b| a+1..b} #=>[0..1, 2..4, 5..10,
11..14, 15..22]
@points.shift
Now i want to save a range for every user.tracks, but don't know how?
First think: create a model track_range(track_id:integer, t_start:integer,
t_end:integer) through has_one relation with track model. I see that
@track.point = @track.track_range.t_end, but how could i set up and save
track_range.t_start?
Second think(more acceptable), create a new column for track
(pre_point:integer). But question the same: how to save a range from
@ranges for each tracks?
Thanks for answers
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/959eaba2-0c3b-466c-80c1-4029c58a0146%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.