Dave Castellano wrote in post #1140813:
> Is play_list an instance of a model? If so then why is
> sequence_questions not just a method of the model?
>
> Colin
>
> Yes it is. I'll try that now.
>
> Thank you.
>
> Dave Castellano
Well, maybe...
Here is the code, te question is is it an instance if its not yet
created?
# POST /drills
# POST /drills.json
def create
if params[:level] == "subject"
session[:scope_id] = session[:student_subject_id]
session[:scope] = "subject"
elsif params[:level] == "book"
session[:scope_id] = session[:student_book_id]
session[:scope] = "book"
elsif params[:level] == "chapter"
session[:scope_id] = session[:student_chapter_id]
session[:scope] = "chapter"
end
if !Drill.exists? user_id: current_user.id, scope: params[:level],
scope_id: session[:scope_id]
if params[:level] == "subject"
klass = ScopeSelector::Subject
scope_id = session[:student_subject_id]
elsif params[:level] == "book"
klass = ScopeSelector::Book
scope_id = session[:student_book_id]
elsif params[:level] == "chapter"
klass = ScopeSelector::Chapter
scope_id = session[:student_chapter_id]
end
scope_selector = klass.new(scope_id)
play_list = scope_selector.play_list
# play_list[0] contains question ids corresponding to minisection
id in play_list[1]
# play_list[1] contains the minisection_id of the question ids in
play_list[0]
# play_list[2..infinity] contain upcoming minisection ids waiting
to be converted to their corresponding question ids
=begin
initial_now_playing_length = play_list[0].length
now_playing = play_list[0] # Create the now_playing from the long
list by shifting starting_now_playing_length question id's fron question
pool.
clone_number = 3 # $$$Variable # Number of repeats of
now_playing used to create initial playlist
order = "random" # $$$Variable
if order == "random"
now_playing_temp = Array.new
for i in 1..clone_number
now_playing = now_playing.dup.shuffle
now_playing_temp = now_playing_temp + now_playing
end
now_playing = now_playing_temp
for d in 1..clone_number # Check for sequential duplicates:
if now_playing[(initial_now_playing_length * d) -1 ] ==
now_playing[initial_now_playing_length * d] # Finds a duplicate...
value = now_playing.delete_at(initial_now_playing_length *
d) # Get the item and delete it from array
now_playing.insert(now_playing.length, value) # Reinsert
the item in a new position
end
end
else # Sequential
now_playing = now_playing.dup * clone_number
end
=end
now_playing = play_list[0].sequence_questions
binding.pry
play_list[0] = now_playing
@question = Question.find(play_list[0][0])
session[:play_list] = play_list
@drill = Drill.new(play_list: play_list, scope: params[:level],
scope_id: scope_id, user_id: current_user.id)
if @drill.save
redirect_to(:controller => "questions", :action => "show", :id
=> @question)
else
redirect_to :back
end
else # Drill already exists
@existing_drill = Drill.where("user_id = ? AND scope = ? AND
scope_id =?", current_user.id, params[:level],
session[:scope_id]).first.play_list
session[:play_list] = @existing_drill
@question = @existing_drill[0][0]
redirect_to(:controller => "questions", :action => "show", :id =>
@question)
end
end
The code between begin and end is the code I need to use in more than
one method...
Dave
--
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/77ccef418dedf6bd00b24c87f8ff6b45%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment