ok let me explain you in your code following is your code
1: <div id="content"> 2: <%= debug navbar.all_modules %> now the navbar is undefined , please replace navbar to *Navbar* capital *N*that is your Model name see in this line class *Navbar *< ActiveRecord::Base now try this and let me know ~N A R E N On Tue, Jun 16, 2009 at 4:04 PM, Ritvvij <[email protected]> wrote: > > This is like a reference table which doesnt need a controller :| > And it is a reftable for what links to display on screen. > > This is what I did finally. > > class Navbar < ActiveRecord::Base > def self.all_modules > NavBar.find (:display_name, :url, :conditions => {:name => > 'module_bar'}, :order => 'sort_order') > end > def self.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 self.associated_module (selected_quick_link) > NavBar.find (:group_by_module, :conditions => {:name => > 'quick_links_bar', :display_name => selected_quick_links}) > end > end > > And I am still getting > undefined local variable or method `navbar' for #<ActionView::Base: > 0x4be1140> > Extracted source (around line #2): > 1: <div id="content"> > 2: <%= debug navbar.all_modules %> > > Please help > > > On Jun 16, 1:04 am, Narendra sisodiya <[email protected]> > wrote: > > agree with Nayak, > > > > If you didn't create the object *navbar* than it will through the > exception > > that is in your case. > > > > or define static methods like I did and use directly by model name. > > > > Avoid direct model's method calls in view , use helper file or controller > as > > suggested by Nayak. > > > > ~N A R E N > > > > On Tue, Jun 16, 2009 at 11:08 AM, NAYAK <[email protected]> wrote: > > > Hi > > > > > QUESTION --- I want to access these methods from views directly. When > > > I do <%= debug navbar.all_modules %> it fails. It cannot find the > > > navbar. > > > > > This will work fine only if you have navbar as an object of your Navbar > > > model, confirm whether you have done the same. > > > As I observe that your method in model does not have anything related > to > > > specific object of the class, you can have it as a class method by > defining > > > it as self.all_modules. This can be directly used by Navbar.all_modules > > > > > Note: One should not use model methods in views directly. Use > controller > > > objects or helpers for the same. > > > > > - Nayak > > > > > On Tue, Jun 16, 2009 at 10:55 AM, Narendra sisodiya < > > > [email protected]> wrote: > > > > >> can you tell me what you did exactly ? > > > > >> On Tue, Jun 16, 2009 at 9:43 AM, Ritvvij <[email protected]> wrote: > > > > >>> Did what you said.. > > >>> Now getting error --- "undefined local variable or method `navbar' > for > > >>> #<ActionView::Base:0x4dfce0c>" > > > > >>> On Jun 15, 10:54 pm, Narendra sisodiya <[email protected]> > > >>> wrote: > > >>> > 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 > > > > > -- > > > - NAYAK > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

