query not displaying proper result

Posted by ravindra on Stack Overflow See other posts from Stack Overflow or by ravindra
Published on 2011-06-23T12:53:49Z Indexed on 2011/06/23 16:22 UTC
Read the original article Hit count: 183

Filed under:

In my Rails 3 project I have the following code for

  1. My controller:

    class TasksController < ApplicationController
    
      def today
        @tasks = Task.today
        @task = Task.new
        respond_to do |format|
          format.html { render :text=> "Sorry , you don't have any task pending today." }
    
          format.html # new.html.erb
          format.xml  { render :xml => @tasks }
        end
      end
    
      def this_week
        @tasks = Task.this_week
        @task = Task.new
        respond_to do |format|
          format.html { render :text => "Sorry , No content for selected period." }
    
          format.html # new.html.erb
          format.xml  { render :xml => @tasks }
        end
      end
    end
    
  2. My model:

    class Task < ActiveRecord::Base
    
      def self.today
        Task.where(:due_date => "Date.today" , :task_status => "open").order("due_date ASC")
      end
    
      def self.this_week
        Task.where(:due_date =>"Time.now.this_week" , :task_status => "open" ).order("due_date ASC")
      end
    end
    

Why it does not displaying anything in the relative view. Please help me.

Thanks

© Stack Overflow or respective owner

Related posts about ruby-on-rails-3