Привет Ваш код может быть что-то вроде
time = Time.now
@book = Book.find(:all, :conditions = > [" created_at >= '#{Time.utc(time.year, time.month, time.day, time.hour, time.min - 1)}'"]) // .first if you're sure that it'll return just one record
if @book.blank? //.blank? not .nil? because the result of find is [] not nil
# Just incase we didn't create a book, we'll initialize one
@book = Array.new() //if you're sure that find'll return just one book you may don't change your code here
@book.first = Book.create()
end
//if you're sure that find'll return just one book you may don't change your code here
@book.each do |book|
@chapters = @book.chapters.build etc.............
end
, если вы ищете книгу, созданную каким-либо пользователем, вы должны передать user_id
этому методу, и ваши условия будут
:conditions = > [" created_at >= '?' AND author_id = ?", Time.utc(time.year, time.month, time.day, time.hour, time.min - 1), params[:author_id]])