Hi all, I''ve got a feeling this is a quite simple question, but after searching for an answer don''t know where to start! What I''d like in my app is to have a button, that the user can press, which then runs a function, and then refreshes the page. The function itself will go off and look at another url, and possibly save some data, but I haven''t got that far yet, I cant even get it to run a function. my view code (index) looks like this ... <%= button_to("BAnd Name", :action => ''search_url'') %> ... my controller code has the ''search_url'' function def search_url render ''index'' end loading the page gives the error No route matches {:action=>"search_url", :controller=>"edinburgh"} which suggests it''s trying to go to the page edinburgh/search_url, I dont want it to do this, just run the function, then render index again, is this possible? Should I be using a different function to search_url? Or am I missing something very basic about how websites receive commands, does every function I execute have to be run from a url address? What if I want to pass in arguments to the function, such as {:action=>"search_url(:bandName => ''The Beatles'')"} is this possible?? so many questions, sorry just don''t know where to begin!? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 2 December 2010 18:31, Michael Baldock <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi all, > > I''ve got a feeling this is a quite simple question, but after searching > for an answer don''t know where to start! > > What I''d like in my app is to have a button, that the user can press, > which then runs a function, and then refreshes the page. The function > itself will go off and look at another url, and possibly save some data, > but I haven''t got that far yet, I cant even get it to run a function. > > my view code (index) looks like this > > ... > <%= button_to("BAnd Name", :action => ''search_url'') %> > ... > > my controller code has the ''search_url'' function > > def search_url > > render ''index'' > > end > > loading the page gives the error > > No route matches {:action=>"search_url", :controller=>"edinburgh"} > > > which suggests it''s trying to go to the page edinburgh/search_url, I > dont want it to do this, just run the function, then render index again, > is this possible? > > Should I be using a different function to search_url? > > Or am I missing something very basic about how websites receive > commands, does every function I execute have to be run from a url > address?You got it. All the browser can do is access a url on the server. So in a rails app everything is done via actions in a controller.> > What if I want to pass in arguments to the function, such as > {:action=>"search_url(:bandName => ''The Beatles'')"} is this possible??You can pass params to a url (as is done with show, edit and so on, here the id is passed). It would be coded :action => search_url, :bandName => ''The Beatles''.> > so many questions, sorry just don''t know where to begin!?I think maybe you need to do some research into basic html and how the web works (have a look at w3schools maybe). Then have a look at the Rails Guides, starting with Getting Started obviously. Then maybe move on to some tutorials such as railstutorial.org. Good luck Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks for your help Colin, I''ll do a bit more basic research before getting back to the problem in hand! M -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote in post #965787:> On 2 December 2010 18:31, Michael Baldock <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> my view code (index) looks like this >> >> >> Should I be using a different function to search_url? >> >> Or am I missing something very basic about how websites receive >> commands, does every function I execute have to be run from a url >> address? > > You got it. All the browser can do is access a url on the server. So > in a rails app everything is done via actions in a controller.[...] Just to clarify this point for the OP, let me state explicitly that this is just the way the Web works. The browser only sends HTTP requests to the server (for specific URLs) and processes the results. It has no way of knowing (nor should it care) anything about the nature of the server-side application. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.