Hi Shahroon
It looks like you are creating a resource for leads, and that you want to
display these leads in the dashboard for your application.
What you can do is create a controller for leads. Then you have a resource
=> :leads.
In your routes file you can map the route of your application to the
leads_controller.
map.root :controller => 'leads', :action => 'index'
You can also add a named route like so
map.dashboard '/dashboard', controller => 'leads', :action => 'index'
This will still allow you to use dashboard_path.
If you want to move the query to your Lead model you can do it like this:
in the controller
@dashs = Lead.some_method_name
And then in the lead model
def self.some_method_name
.find_by_sql("(SELECT
opportunities.created_on,opportunities.created_by,opportunities.position_title
FROM opportunities) UNION DISTINCT
(SELECT customers.created_on,customers.created_by,customers.company_name
FROM customers) UNION DISTINCT
(SELECT
leads.created_on,leads.created_by,leads.first_name FROM leads)
ORDER BY created_on DESC")
end
or
class << self
def some_method_name
find_by_sql("(SELECT
opportunities.created_on,opportunities.created_by,opportunities.position_title
FROM opportunities) UNION DISTINCT
(SELECT customers.created_on,customers.created_by,customers.company_name
FROM customers) UNION DISTINCT
(SELECT
leads.created_on,leads.created_by,leads.first_name FROM leads)
ORDER BY created_on DESC")
end
end
Regards
Ivor
On Wed, Dec 24, 2008 at 12:10 PM, shahroon ali <[email protected]>wrote:
> Hi All, I want to shift my Method from Controller to Model, I have
> a controller with no Model because there is no table. Now I want to shift my
> Method from Controller to Model. The code is here..
> //////////Dashboard Controller////////////////////////
> class DashboardController < ApplicationController
> layout 'standard'
> def index
> @dashs = Lead.find_by_sql("(SELECT
> opportunities.created_on,opportunities.created_by,opportunities.position_title
> FROM opportunities) UNION DISTINCT
> (SELECT
> customers.created_on,customers.created_by,customers.company_name FROM
> customers) UNION DISTINCT
> (SELECT
> leads.created_on,leads.created_by,leads.first_name FROM leads)
> ORDER BY created_on DESC")
>
> @dashboards = @dashs.paginate :per_page => 3,:page => params[:page]
>
> end
>
> end
>
> Now I want to make a Model for Dashboard and shift my queries from
> Controller to Model.
>
> Thanks & Regards,
> Shahroon
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---