Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3282612
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:56:51+00:00 2026-05-17T19:56:51+00:00

In my controller I’d like to do something like the following: @book = Book.find(:all,

  • 0

In my controller I’d like to do something like the following:

@book = Book.find(:all, :conditions = > [" created_at > with in the last 1 minute "]

if @book.nil?
  # Just incase we didn't create a book, we'll initialize one
  @book = Book.create()
end

@chapters = @book.chapters.build etc.............

* In sum, when the user is uploading a chapter, if they’ve recently created a book, I want the chapter to automatically go to that book and to make a new book.

Thoughts? thank you all

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:56:51+00:00Added an answer on May 17, 2026 at 7:56 pm

    Hi Your code may be something like

    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
    

    if you’re looking for a book created by some user you must pass user_id to this method and your conditions’ll be

    :conditions = > [" created_at >= '?' AND author_id = ?", Time.utc(time.year, time.month, time.day, time.hour, time.min - 1), params[:author_id]])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

controller code that doesn't work: @mailings = Mailing.find(:all, :conditions => [created_at.month = ?, m])
My controller: def toppen @top = Konkurrancer end My view: <ul id=random> <% @top.find(:all,
My controller has the following code cookies[:book] = { :value => Kids Puzzles, :expires
My Controller (User Controller) def reset_password @user = User.find_by_reset_code(params[:reset_code]) unless params[:reset_code].nil? if request.post? if
My Controller (User Controller) def reset_password @user = User.find_by_reset_code(params[:reset_code]) unless params[:reset_code].nil? if request.post? if
Controller: class GalleriesController < ApplicationController def index @galleries = Gallery.all end end View: <%
my controller is like this $content = View::factory('user/biochemistryTestForm') ->bind('result', $result); $this->template->content = $content; //here
the controller looks like this class App.ContactsController extends Tower.Controller index: (params) -> @set('person', App.HighrisePerson.create())
My controller method just return String value. When I called JSON from my view
My controller has to enumerate all the areas in the application. Is it possible?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.