Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Course Queries Syllabus Queries 2 years ago
Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
How do I create a nested form for 2 scaffolded models?
I have a Syllabus model, which has many Missions. Previously, the only way to create Missions was through the Syllabus nested form (which I made with Railscasts). Yesterday, I decided that users should be able to create Missions by itself, so I scaffolded the Missions while skipping the migrations, so it created all the controllers and views for the existing Missions Model.
So here's the problem: I can now create Missions by itself, but when I try to create Missions through the Syllabus nested form, it gives me an error "undefined method `difficulty' for #<\Mission:0xb372ffc.>" I'm guessing it's trying to pass in the Syllabus attributes to the Missions attribute, which isn't defined in the Missions schema. (difficulty is an attribute only for Syllabus).
To sum up: Nested forms worked with "builder" when I only had Model for Missions, but when I scaffolded the Missions so it could exist by itself, I couldn't use the nested form.
Because there were more than a couple files that may affect this, I created a gist.https://gist.github.com/2631734
Btw, these are the params that should be passed in
{"utf8"=>"✓", "authenticity_token"=>"YxkzNmIJl0jBA467tdHP2zqNv22DgKrzSx+WCFgwKtk=", "syllabus"=> {"category"=>"Technology and Internet", "difficulty"=>"Beginner", "title"=>"missions testing", "description"=>"deccrip", "missions_attributes"=> {"0"=> {"_destroy"=>"false", "title"=>"plz", "content"=>"\r\n\tdad\r\n" } } }, "commit"=>"Create Syllabus" }
\r\n\tdad
My best guess is that creations in
creations
current_user.creations.build(params[:syllabus])
refers to a collection of mission instead of syllabus. Its kindof hard to determine without the full error and user model.
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
Course Queries 4 Answers
Course Queries 5 Answers
Course Queries 1 Answers
Course Queries 3 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.