I want to make a dashboard page with on top a create action (form) and underneath it a list action… (to display all the questions that have been made) I was wondering what is the best way to do this.
I have a QuestionsController with a list and a create action. So i do need to make a DashboardController with a createlist action…? And there render the two templates from the QuestionController…?
Or do i need to make a DashboardController with both the list and create actions on them refering to the Questions model?
Best regards,
Thijs
You should create QuestionsController, with form partial included on index view. This form should simply follow to create action, and this action should at error (remember that there could be validation errors) render index action, and after success it should redirect back to index.
Unless you also need to create questions from other places, then it’s more complicated.
UPDATE:
You could also create DashboardsController, but I would only use it to display dashboard (show action and singular resource, not resources in routes.rb), and then normally follow new question form to QuestoinsController#create, and redirect back to DashboardsController#show. This way it’s more RESTful if you also show more than one resource type on dashboard, because you show singular dashboard (with questions and other resources), but you follow to QuestionsController#create to create Question.
UPDATE 2:
To make it in one place if you (or anyone else needs):
In your
routes.rbfile define resources:In your
QuestionController:In your
app/views/questions/index.html.erbview:in
app/views/questions/_form.html.erbyou just define your standard form for new question:Then you don’t need view for
newaction, as this action would just display form for new question, and you have this form inindexaction.