i am new to Ruby on Rails.
I am trying to make a one to many association. I have a “Project” and the Project should have many “Taskbundle”.
That is looking fine.
Now i want to show on the page only the taskbundles filtered for that selected project.
I made this in the ProjectController class:
def select
puts "==Projects=="
puts params[:id]
@project = Project.find{params[:id]}
puts @project.id
session[:project_id] = @project.id
puts session[:project_id]
redirect_to taskbundles_path
end
I am getting there without problem, but the find method finds the project with the id 3 and not the project with the id 4 ? I checked, the project with id 4 exists.
Output
==Projects==
4
3
3
Started GET "/projects/select/4" for 127.0.0.1 at 2013-01-05 20:19:03 +0100
Processing by ProjectsController#select as HTML
Parameters: {"id"=>"4"}
?[1m?[35mProject Load (0.0ms)?[0m SELECT "projects".* FROM "projects"
Redirected to http://localhost:3000/taskbundles
Completed 302 Found in 3ms (ActiveRecord: 0.0ms)
I have no idea where i did a mistake?
I think you got a syntactic problem:
@project = Project.find{params[:id]}should be@project = Project.find(params[:id]). The ID needs to be passed as an argument. Your code creates a ruby block.