Load model to array in rails -


if save array using @levels.each(&:save) how load model level? is: appropriate command repopulate array saved data

@levels = level.find_all 

does not seem exist, pretty new see, want store , load, levels!

here's gamescontroller:

def initialize @levels = [] unless @levels @levels = levels 

end

def add_level   levels << level.new   levels.each(&:save)   redirect_to edit_game_path(params[:id]) end 

and model:

class game < activerecord::base   has_many :levels end 

if association :

game has many levels , level belongs game.

then, @game = game.find_by_id(params[:id]) #whoesoever game page @levels = @game.present? ? @game.levels : []

i hope, understood problem


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -