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.
I have an app where users can create courses, and each course has_one syllabus. How could I go about configuring my courses and syllabuses (I know it's Syllabi but apparently Rails doesn't) controller, and my routes, so on a course's page there is a link to create or show the course's syllabus, and a link back to the course from the show syllabus page?
In my routes I have:
resources :courses do resources :syllabuses member do put :enroll #this is so users can enroll in the course end end
Currently , so the course_id will be saved in the syllabus table in my courses_controller, I have:
def create_syllabus @course = Course.find(params[:id]) @syllabus = @course.build_syllabus(params[:syllabus]) if @syllabus.save redirect_to @syllabus, notice: "Successfully created syllabus." else render :new end end
then in my courses show page I have:
<section> <% if (current_user.courses.includes(@course) || current_user.coursegroups.find_by_course_id_and_role(@course.id, "admin")) %> <%= render 'create_syllabus' %> <% end %> section>
then in my create_syllabus form (in my courses views folder) I have tried starting it off with:
# I have @course = Course.find(params[:id]) defined in show in the #courses_controller <%= form_for @course.create_syllabus do |f| %> <%= form_for @course.syllabus.create_syllabus do |f| %> <%= form_for @course.syllabus.create do |f| %>
and I get an undefined method error for each of those.
If you want to create a new syllabus in your show action of a specific course, you can add this to your controllers and views:
syllabus
show
course
courses_controller.rb
@course = Course.find(params[:id]) # Build a new @syllabus object, only if there is none for the current course unless @course.syllabus @syllabus = @course.build_syllabus end
views/courses/show.html.erb
# Show the syllabus name if there is one, or show the form to create a new one <% if @course.syllabus.name %> <p>Syllabus: <%= @course.syllabus.name %>p> <% else %> <p>Create Syllabus:p> <%= form_for([@course, @syllabus]) do |f| %> <div class="field"> <%= f.label :name %><br /> <%= f.text_field :name %> div> <div class="actions"> <%= f.submit %> div> <% end %> <% end %>
syllabuses_controller.rb
def create @course = Course.find(params[:course_id]) # Build new syllabus object based on form input @syllabus = @course.build_syllabus(params[:syllabus]) if @syllabus.save # redirect to /course/:id redirect_to @course, notice: 'Syllabus was successfully created.' } end end
course.rb
class Course < ActiveRecord::Base attr_accessible :name has_one :syllabus end
syllabus.rb
class Syllabus < ActiveRecord::Base belongs_to :course attr_accessible :name, :course_id end
Some things that I left out but you should still include:
if @course.syllabus.name
if/else
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.