Reputation: 427
rails generate scaffold controller sportler name:string
rails generate model einheit ... sportler_id:integer
/app/controllers/sportlers_controller.rb
..
def add_einheit
sportler = Sportler.find(params[:id])
@einheit = Einheit.new(:sportler => sportler)
render :template => "einheits/edit"
end
..
/app/views/sportles/index.html.erb - when i cut this source code below the route error
doesnet appear anymore
..
<td><br>
<%= link_to "Trainingseinheit hinzufügen", :action => "add_einheit", :id => sportler %><br>
</td><br>
..
routes.rb
FITAPP2::Application.routes.draw do
resources :sportlers
Routing Error
No route matches {:action=>"add_einheit", :id=>#groesse: "3", created_at: "2012-12-27 15:56:04", updated_at: "2012-12-27 15:56:04">,
:controller=>"sportlers"}
Try running rake routes for more information on available routes.
Upvotes: 1
Views: 341
Reputation: 427
I took Kaders solution. It functions but now i geht the next Routing Error. action => sportlers/update_einheit doesnt function. I dont understand the princip.
FITAPP2::Application.routes.draw do resources :sportlers do member do get "add_einheit" get "update_einheit" end end end
I try to extends the routes above with a second entry get update_einheit - it doenst function Routing Error
No route matches {:action=>"update_einheit", :id=>#, :controller=>"sportlers"} Try running rake routes for more information on available routes.
rake routes:
add_einheit_sportler GET /sportlers/:id/add_einheit(.:format) sportlers
update_einheit_sportler GET /sportlers/:id/update_einheit(.:format) sportlers
sportlers GET /sportlers(.:format) sportlers
POST /sportlers(.:format) sportlers
new_sportler GET /sportlers/new(.:format) sportlers
edit_sportler GET /sportlers/:id/edit(.:format) sportlers
sportler GET /sportlers/:id(.:format) sportlers
PUT /sportlers/:id(.:format) sportlers
DELETE /sportlers/:id(.:format) sportlers
Upvotes: 0
Reputation: 31
Are you sure you have a html file under sportlers view folder, like view/sportlers/add_einheit.html.erb ?
Upvotes: 0
Reputation: 4934
As routing error suggest you should "try running rake routes for more information on available routes." The point is you obviously have not specify route rule for add_einheit method
Upvotes: 1
Reputation: 31
resources :sportlers
This code will only creates routes about CRUD actions(create,new,edit,update vss...) To use "add_einheit" actions edit routes.rb ;
resources :sportlers do
member do
get "add_einheit"
end
end
If you send a parameter like "id" use "member do" else use "collection do" in your routes.rb file.
Upvotes: 0