views:

266

answers:

0

Hello there, I'm struggling to get this working.

I have the following routes:

 map.namespace :admin do |admin|
      admin.resources :languages do |language|
           language.resources :courses
      end
 end

So, basically an admin namespace and the languages models which has_many courses and obviously a course belongs_to language.

then on my controller

def show
    obj = Language.find(params[:language_id]).courses.find(params[:id])
    render :partial => "form", :object => obj, :layout => "admin/layouts/application"
end

def new
    obj = Language.find(params[:language_id]).courses.new
    render :partial => "form", :object => obj, :layout => "admin/layouts/application"
end

and finally on the partial view being rendered....

form_for [:admin,:language,object], :html => {:multipart => true} do |f|...

But unfortunately this just works for:

http://localhost:3000/admin/languages/1/courses/new

and not for

http://localhost:3000/admin/languages/1/courses/6 for example

so for the show I'm getting an error for generate the admin_language_course_url and the error is something like:

 admin_language_course_url failed to generate from {:action=>"show", :controller=>"admin/courses", :language_id=>#<Course id: 6, title: "ahaha!!", description: "121212", location: "12", category: "long", start_at: "2010-06-07...

and I believe this means that the show is taking the language/:language_id as language/:id that which is the course ID.

So the question is...how to use the same declaration work on both new and show methods?

Thanks in advance