For accessing model method from view , you can define self methods in model
and than directly access by ModelName.methodName
For example
class Navbar < ActiveRecord::Base
def self.all_modules
Ur stuff
end
end
in view
<% Navbar.all_modules %>
~
N A R E N
On Tue, Jun 16, 2009 at 9:02 AM, Ritvvij <[email protected]> wrote:
>
> Hi
> I have a model called navbar. It does not have a view or a controller
> defined.
>
> create_table :navbars do |t|
> t.string :name
> t.string :display_name
> t.string :url
> t.string :group_by_module
> t.boolean :default_link
> t.integer :sort_order
>
> And in the model I have written few methods.
>
> class Navbar < ActiveRecord::Base
> def all_modules
> NavBar.find (:display_name, :url, :conditions => {:name =>
> 'module_bar'}, :order => 'sort_order')
> end
> def associated_quick_links (selected_module)
> NavBar.find (:display_name, :url, :default_link, :conditions =>
> {:name => 'quick_links_bar', :group_by_module =>
> selected_module}, :order => 'sort_order')
> end
> def associated_module (selected_quick_link)
> NavBar.find (:group_by_module, :conditions => {:name =>
> 'quick_links_bar', :display_name => selected_quick_links})
> end
> end
>
> QUESTION --- I want to access these methods from views directly. When
> I do <%= debug navbar.all_modules %> it fails. It cannot find the
> navbar.
>
> Can someone please guide me?
> Thanks in advance
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---