Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Rails 4 - Nested resource routing

General Tech Learning Aids/Tools
Max. 2000 characters
Replies

usr_profile.png
Deepak Parmar

User

( 5 months ago )

 

I have a course and syllabus models defined like this

class Course < ActiveRecord::Base
    has_many :enrollments
    has_many :students, through: :enrollments, class_name: "User"
    has_many :syllabuses

end

class Syllabus < ActiveRecord::Base
    belongs_to :course
end

Routes defined like this

resources :courses do
    resource :syllabuses
  end

My html has a link to edit syllabus

<td><%= link_to "Edit", edit_course_syllabuses_path, class: "btn btn-primary"  %></td>

rake routes shows me this

edit_course_syllabuses GET    /courses/:course_id/syllabuses/edit(.:format) syllabuses#edit

server log shows the request processing like

Started GET "/courses/46/syllabuses/edit" for ::1 at 2015-02-04 20:55:43 +0530
Processing by SyllabusesController#edit as HTML
  Parameters: {"course_id"=>"46"}
  Syllabus Load (0.3ms)  SELECT  "syllabuses".* FROM "syllabuses" WHERE "syllabuses"."id" = $1 LIMIT 1  [["id", nil]]
Completed 404 Not Found in 2ms

ActiveRecord::RecordNotFound - Couldn't find Syllabus with 'id'=:

How to pass the syllabus id to the syllabus controller edit action ?

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif