Well i just didn't think about the option.
Thank you a lot , i got it now. Can i ask you another Question?

I have different Buildings and it should be possible to upgrade these
buildings.

So my link to count the points looks like this now:

<%= link_to 'Update', village_path(@village), :method => :put %>

It uses the conventional update action now, but writing the code for
an Building_upgrade action in this update action doesn't sound good to
me. So can i write an action in the village controller and use it like
this?

<%= link_to 'Update', village_path(@village), :method
=> :put , :action => building_upgrade %>

or how can i handle this?



On 11 Aug., 18:58, 7stud -- <[email protected]> wrote:
> Genji wrote in post #1016197:
>
> > Hello all,
>
> > i want to create a method that i can use to update/count the points of
> > a village/user in my browser game. Every time the user clicks on a
> > link, the method should be used. The links should look something like
> > that :
>
> > <%= link_to('Update', village_path, :method => :update_points) %>
>
> > right or not?
>
> Not.  In rails, a method within a controller is called 'an action'--not
> 'a method'.  In the http protocol, which is the syntax everyone agrees
> to use over the internet, the 'method' is usually GET or POST, which
> specifies how data is to be sent over the internet.  If you don't know
> the difference, do some research.  Therefore, when you write:
>
> :method => :update_points
>
> that is wrong because it does not specify 'get' or 'post' for the
> method.  By default, links use the method GET.  If you want to change
> some data on the server, then you should specify POST.
>
> The action that the link_to goes to can be tricky to figure out.  rails
> will automatically work out what action it should execute based on the
> path you specify and the method(= get or post).  See the chart in
> section 2.2 here:
>
> http://guides.rubyonrails.org/routing.html
>
> Note that the '/photos' path will cause rails to execute a different
> action depending on the method.  If the automatic routing doesn't work
> for you,  you can specify the controller and the action in link_to
> (instead of a path):
>
> <%= link_to "Click me",
>             {:controller => 'users', :action => 'get_info'} %>
>
> Sometimes you don't even have to specify a path and rails will still
> figure out where to go.  See the examples in the link_to docs:
>
> http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#...
>
> You have another problem, too.  You used the 'named route':
> village_path.  village_path requires an argument, which may look like
> this:  village_path(@village).  Compare that to the named route:
> villages_path.
>
> > So when you see :method it
> > The question is now: Where do i write this method? I did a test in the
> > village_controller:
>
> > def update_points
>
> >     @village = Village.find(params[:id])
>
> >     @village.points = 120
> >     @village.save
>
> > end
>
> > can this work?
>
> Why don't you want to use the conventional update action?  Also, what
> page do you want your rails app to send back in response to the update?
> Do you want your app to remain on the same page?  Remember that when you
> call an action, rails automatically sends back a page to the browser
> that matches the
> action name, e.g. rails converts update_points.html.erb. into
> update_points.html and sends it back to the browser.  Then the browser
> loads the page.
>
>
>
>
>
>
>
>
>
>
>
> > cause when i click on the link i just get :
>
> > No route matches "/villages/12"
>
> > When i open the /villages/12 without the method it works all fine.
> > My routes.rb :
>
> > Citywar::Application.routes.draw do
>
> >   devise_for :users
> >   resources :users, :only => [:index, :show]
> >   resources :villages
> >   root :to => 'pages#home'
>
> > end
>
> > So how can i solve this?
>
> > Best regards
> > Genji
>
> --
> 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 [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