Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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.</p> <p>Unless you also need to create questions from other places, then it's more complicated.</p> <p><em>UPDATE</em>:</p> <p>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.</p> <p><em>UPDATE 2</em>:</p> <p>To make it in one place if you (or anyone else needs):</p> <ol> <li><p>In your <code>routes.rb</code> file define resources:</p> <pre><code>resources :questions </code></pre></li> <li><p>In your <code>QuestionController</code>:</p> <pre><code>class QuestionsController &lt; ApplicationController def index setup_questions end def create @question = Question.new(params[:question]) if @question.save redirect questions_path, :notice =&gt; "Successfully created question." else setup_questions render :action =&gt; :index end end private def setup_questions @questions = Question.order(:name).page(params[:page]) # or any other method to fetch all your questions @question ||= Question.new end end </code></pre></li> <li><p>In your <code>app/views/questions/index.html.erb</code> view:</p> <pre><code>&lt;% @questions.each do |question| %&gt; &lt;%# display question as table row %&gt; &lt;% end %&gt; &lt;% render :template =&gt; "form", :locals =&gt; {:question =&gt; @question} %&gt; </code></pre></li> <li><p>in <code>app/views/questions/_form.html.erb</code> you just define your standard form for new question:</p> <pre><code>&lt;%= form_for question do |f| %&gt; &lt;%# form fields %&gt; &lt;% end %&gt; </code></pre></li> </ol> <p>Then you don't need view for <code>new</code> action, as this action would just display form for new question, and you have this form in <code>index</code> action.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload