Problem on page 137
|
|
At the completion of editing /app/views/workouts/show.rhtml on page 137, I am getting an error when I go to http://localhost:3000/workouts/1 |
|
|
Hi Scott, Could you also send a paste of your routes.rb from /config? Thanks Eldon |
|
|
Here you go: Thanks for your help! |
|
|
Scott, I’m not at home where i can test this but one thing I notice that seems odd is that in your routes.rb on line 7 you do a second call to create a resource for workouts
Since i can’t test it from here – I’m wondering if calling it again is essentially “overwriting” the previous one (on line 2) that had the nested activities resource. If that’s the case that would explain why your getting an error that the route doesn’t exist Could you try changing line 7 to map.resources :exercises, :users and let me know if that helps? Also could you confirm if you’re using Rails 1.6 or Rails 2.0? |
|
|
I changed routes.rb. Didn’t help. Same error: I’m on Rails 2.0.1. |
|
|
Ahh…. Rails 2 introduced some changes to the ways that routes are generated and I’m betting that’s the problem that you’re encountering. In Rails 2 – nested routes are automatically assigned a name prefix to help avoid naming conflicts. So in Rails 2 – the correct route would be workout_activities_path(@workout) The advantage of this is that you could have both a direct route and a nested route to the activity resource. So if you want to try and build this project within Rails 2 – then you’ll either have to change all the named routes for activities to include the workout_ named prefix or you could simply add a :name_prefix => nil to the nested activities route. Let me know if that helps / makes sense Eldon |
|
|
So do you mean that I should insert workout_ before every instance of activities_path? I tried that (changes in activities/new and ../show, and workouts/show) which generated… NoMethodError in ActivitiesController#create undefined method `new_exercise=’ What does :name_prefix => nil do? I tried adding it to routes.rb…
...which generated a NameError undefined…`name prefix’ |
|
|
It looks like you forgot the colon in front of name_prefix in your route. name_prefix is a symbol and needs the colon in front of it to work. So it should be: map.resources :workouts do |workout| workout.resources :activities, :name_prefix => nil end But yeah, otherwise you would need to add that workout_ prefix in front of every occurence of an activities named route (such as activities_path or activities_url) in order for it to work. The project was built in Rail 1.2.6 and all the named routes would need to be converted to the changes in routing that Rails 2.0 introduced if you don’t want to run it in Rails 1.2.6. A good trick to help you convert the routes is that there’s a new rake task that will show you your routes – just run rake routes from the root of your application. |
|
|
Tried both. Getting same errors as previously described. |
|
|
Scott, You’re still getting the undefined method `activities_path’ error message? Obviously there will be some challenges in converting the project to Rails 2.0 but that seems odd that you can’t get past this one. Would you mind zipping up the app in it’s current state and emailing it to my gmail account ( alameda.eldon ) and I’ll take a look at it over the weeekend? |
|
|
Yes, same error. I sent my version of the app to you. Thanks |
|
|
Scott, Just sent the code back to you and it should be working now. Eldon |
|
|
Thanks for your help! |