Still learning, but it is getting easier by the minute ;) I have a bunch of controllers (that correspond to db tables) and corresponding views. However, I want to use the views with link_to_remote into divs on a page that is created as a "base" that is loaded WITHOUT making any calls on the db. To this end I created a dud controller, main, with a single empty method def load end and a corresponding view that is the html "base". This works fine, but I wanted to check and see if there are any caveats against doing this (using a seperate dud controller) or if there is a more "conventional" way to go. I could put the empty method into a real, existing controller, I just figured "main/load" would be tidier... -- Posted via http://www.ruby-forum.com/.
I notice you cannot access another controller method from a view, eg. :action => "othersec/list" is no good; the action must belong to the corresponding controller That being the case, I might as well just have one controller, "main", with methods like "list_that" and "list_this", ie, there is not much point in defining a controller for each table -- all that is needed is class definition in models/ However "what seems to be the case" to me is not necessarily the way that it is -- I''m worried I may diverge too much from anything resembling *Best Practices* here, particularly since this means going script/generate controller this then erasing everything but the model definition (I tried erasing those two, and creating one "main.rb" with all the classes in, but then there is an error). Anyone have any thoughts on this? After a bit of googling I found some stuff about inheritance governing this -- does that mean I should put the methods I want globally accessible in app/controllers/application_controller.rb? -- Posted via http://www.ruby-forum.com/.
2009/5/23 Mk 27 <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>> > I notice you cannot access another controller method from a view, eg. > > :action => "othersec/list" > > is no good; the action must belong to the corresponding controllerNot sure I follow you here, you can certainly link to a different controller from a view, what is that you are trying to do? Colin> > > That being the case, I might as well just have one controller, "main", > with methods like "list_that" and "list_this", ie, there is not much > point in defining a controller for each table -- all that is needed is > class definition in models/ > > However "what seems to be the case" to me is not necessarily the way > that it is -- I''m worried I may diverge too much from anything > resembling *Best Practices* here, particularly since this means going > > script/generate controller this > then erasing everything but the model definition (I tried erasing those > two, and creating one "main.rb" with all the classes in, but then there > is an error). > > Anyone have any thoughts on this? After a bit of googling I found some > stuff about inheritance governing this -- does that mean I should put > the methods I want globally accessible in > app/controllers/application_controller.rb? > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Colin Law wrote:> Not sure I follow you here, you can certainly link to a different > controller > from a view, what is that you are trying to do? > > ColinThat is what I am trying to do, perhaps this is a syntax problem. If I have three controllers under app/, "aone", "atwo", "athree", all of them have a method "list", in the view for aone I want to call the list method from atwo, so I tried :action => "atwo/list" This is a no go -- what''s the proper syntax? Also (another sort of related syntax question), how can I use a parameter with the methods? Here''s a line which works in a view: <li class="link" onclick="<% remote_function(:update => "album_box", url => { :action => "list_albums" }) %>"> and here is one which returns "undefined local variable or method `url''", the only difference being I tried to pass a parameter via the action <li class="link" onclick="<% remote_function(:update => "album_box", url => { :action => "list_albums(#{artist.id})" }) %>"> ^ oh no! I tried this a few different ways and am about to try a few more ;) Is it just the quoting, or what? -- Posted via http://www.ruby-forum.com/.
Just to clarify, artist.id would be defined in the context (since the text content of the <li> is artist.name). I suppose I should order a book on this stuff ASAP... -- Posted via http://www.ruby-forum.com/.
[quote]:action => "atwo/list"[/quote] that should should :controller => ''atwo'', :action => ''list'' -Mike On May 23, 11:01 am, Mk 27 <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Colin Law wrote: > > Not sure I follow you here, you can certainly link to a different > > controller > > from a view, what is that you are trying to do? > > > Colin > > That is what I am trying to do, perhaps this is a syntax problem. > > If I have three controllers under app/, "aone", "atwo", "athree", all of > them have a method "list", in the view for aone I want to call the list > method from atwo, so I tried > > :action => "atwo/list" > > This is a no go -- what''s the proper syntax? > > Also (another sort of related syntax question), how can I use a > parameter with the methods? Here''s a line which works in a view: > > <li class="link" onclick="<% remote_function(:update => "album_box", url > => { :action => "list_albums" }) %>"> > > and here is one which returns "undefined local variable or method > `url''", the only difference being I tried to pass a parameter via the > action > > <li class="link" onclick="<% remote_function(:update => "album_box", url > => { :action => "list_albums(#{artist.id})" }) %>"> > ^ oh no! > > I tried this a few different ways and am about to try a few more ;) Is > it just the quoting, or what? > > -- > Posted viahttp://www.ruby-forum.com/.
2009/5/23 Mike Rose <MFRosengarten-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> > [quote]:action => "atwo/list"[/quote] > > that should should :controller => ''atwo'', :action => ''list'' > > -Mike > On May 23, 11:01 am, Mk 27 <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > Colin Law wrote: > > > Not sure I follow you here, you can certainly link to a different > > > controller > > > from a view, what is that you are trying to do? > > > > > Colin > > > > That is what I am trying to do, perhaps this is a syntax problem. > > > > If I have three controllers under app/, "aone", "atwo", "athree", all of > > them have a method "list", in the view for aone I want to call the list > > method from atwo, so I tried > > > > :action => "atwo/list" > > > > This is a no go -- what''s the proper syntax? > > > > Also (another sort of related syntax question), how can I use a > > parameter with the methods? Here''s a line which works in a view: > > > > <li class="link" onclick="<% remote_function(:update => "album_box", url > > => { :action => "list_albums" }) %>"> > > > > and here is one which returns "undefined local variable or method > > `url''", the only difference being I tried to pass a parameter via the > > action >There is a clue in the error message that says that it does not like url. The reason is that it should be :url. I don''t know whether the rest of it is correct or not. Colin> > > > > <li class="link" onclick="<% remote_function(:update => "album_box", url > > => { :action => "list_albums(#{artist.id})" }) %>"> > > ^ oh no! > > > > I tried this a few different ways and am about to try a few more ;) Is > > it just the quoting, or what? > > > > -- > > Posted viahttp://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---