On 2 December 2010 18:31, Michael Baldock <[email protected]> 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 [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.

Reply via email to