Rails Route Error - route for new does not exist -


i trying make rails 4 app.

i have projects model , project_questions model.

project questions belongs projects.

i have made project questions form users can use ask question project.

my trouble is, when press submit, route error appears saying there no matching route. don't understand because made model through scaffolding understood made main routes automatically.

my structure is:

project_question form (using simple form gem):

  <%= simple_form_for :project_questions |f| %>           <%= f.input :project_id, as: :hidden, input_html: {value: @project_question_id} %>           <%= f.input :title, label: 'question:',  :label_html => {:class => 'question-title'}, placeholder: 'type question here', :input_html => {:style => 'width: 100%', :rows => 4, class: 'response-project'} %>           <%= f.input :content, label: 'is there context or other information?', :label_html => {:class => 'question-title'}, placeholder: 'context might answer question', :input_html => {:style => 'width: 100%', :rows => 5, class: 'response-project'} %>        <br><br><br>           <%= f.button :submit, 'send!', :class => "cpb" %>  <% end %> 

routes:

resources :projects     resources :project_questions       resources :project_answers     end   end 

controller project question:

class projectquestionscontroller < applicationcontroller   before_action :set_project_question, only: [:show, :edit, :update, :destroy]    # /project_questions   # /project_questions.json   def index     @project_questions = projectquestion.all   end    # /project_questions/1   # /project_questions/1.json   def show   end    # /project_questions/new   def new     @project_question = projectquestion.new     @project = project.find(params[:project_id])     # @project_id = params[:project_id]     @project_question.project_answers[0] = projectanswer.new    end    # /project_questions/1/edit   def edit   end    # post /project_questions   # post /project_questions.json   def create     @project_question = projectquestion.new(project_question_params)     @project_question.project_id = project_question_params[:project_id]       respond_to |format|       if @project_question.save         format.html { redirect_to @project_question, notice: 'project question created.' }         format.json { render action: 'show', status: :created, location: @project_question }       else         format.html { render action: 'new' }         format.json { render json: @project_question.errors, status: :unprocessable_entity }       end     end   end    # patch/put /project_questions/1   # patch/put /project_questions/1.json   def update     respond_to |format|       if @project_question.update(project_question_params)         format.html { redirect_to @project_question, notice: 'project question updated.' }         format.json { head :no_content }       else         format.html { render action: 'edit' }         format.json { render json: @project_question.errors, status: :unprocessable_entity }       end     end   end    # delete /project_questions/1   # delete /project_questions/1.json   def destroy     @project_question.destroy     respond_to |format|       format.html { redirect_to project_questions_url }       format.json { head :no_content }     end   end    private     # use callbacks share common setup or constraints between actions.     def set_project_question       @project_question = projectquestion.find(params[:id])     end      # never trust parameters scary internet, allow white list through.     def project_question_params       params[:project_question].permit(:id, :title, :content, :project_id, :user_id,       project_answer_atttibutes: [:id, :answer, :project_question_id, :user_id]       )     end end 

controller project:

class projectscontroller < applicationcontroller   #layout :projects_student_layout    before_action :authenticate_user!      # /projects   # /projects.json   def index     @projects = current_user.projects       #can have more 1 index? need change in routes? if want list related projects , expiring projects - how do within 1 index?      #is there way order these, educators in order of course , students in order of next milestone date?     #@projects.order("created_at desc")   end    # def index2  #    @projects = project.find_xxx_xx  #  end    def list     @projects = project.find(:all)   end    def toggle_draft     @project = project.find(params[:id])     @project.draft = true     @project.save     redirect_to project_path(@project)   end    # /projects/1   # /projects/1.json   def show     #authorise @project      @project = project.find(params[:id])     @creator = user.find(@project.creator_id)     @creator_profile = @creator.profile      #@approver_profile = user.find(@project.educator_id).profile #educators people approve projects #    if profile == 'studnet'     #@approval = @project.approval   #   @invitations = @project.project_invitations    end    # /projects/new   def new     #authorise @project     @project = project.new     @project.scope = scope.new     @project.scope.datum = datum.new     @project.scope.material = material.new     @project.scope.mentoring = mentoring.new     @project.scope.participant = participant.new     @project.scope.funding = funding.new     @project.scope.ethic = ethic.new     @project.scope.group_research = groupresearch.new     @project.scope.backgroundip = backgroundip.new     @project.scope.result = result.new     @project.scope.finalise = finalise.new    end    # /projects/1/edit   def edit     #authorise @project     @project =project.find(params[:id])       end    # post /projects   # post /projects.json   def create     #authorise @project     @project = project.new(project_params)     @project.creator_id = current_user.id     @project.users << current_user     respond_to |format|       if @project.save         format.html { redirect_to @project }         format.json { render action: 'show', status: :created, location: @project }       else         format.html { render action: 'new' }         format.json { render json: @project.errors, status: :unprocessable_entity }       end     end   end    # patch/put /projects/1   # patch/put /projects/1.json   def update     #authorise @project     @project = project.find(params[:id])     @project.creator_id = current_user.id      respond_to |format|       if @project.update(project_params)         format.html { redirect_to @project }         format.json { head :no_content }       else         format.html { render action: 'edit' }         format.json { render json: @project.errors, status: :unprocessable_entity }       end     end   end    # delete /projects/1   # delete /projects/1.json   def destroy     #authorise @project      @project.destroy     respond_to |format|       format.html { redirect_to projects_url }       format.json { head :no_content }     end   end    private     # use callbacks share common setup or constraints between actions.     def set_project       @project = project.find(params[:id])     end      # never trust parameters scary internet, allow white list through.      def project_params       params.require(:project).permit(       :id, :title, :description, :video_proposal, :link_to_video_proposal,       :expiry_date_for_sponsor_interest,  :motivation, :approach,       :completion_date, :start_date, :industry_id,  :recurring_project,       :frequency, :date_for_student_invitation, :date_for_student_interest, :closed, :student_objective,        :industry_relevance, :hero_image, :project_id,       project_question_attributes: [:title, :content, :user_id, :project_id,       project_answer_attributes: [:answer, :project_question_id]],       scope_attributes: [:id, :project_id, :data, :material, :mentoring, :participant, :funding, :ethic, :group, :result, :disclosure, :finalise,                          :if_mentoring, :if_participant, :if_funding, :if_ethic, :if_group_research, :if_backgroundip, :if_datum, :if_material,                          datum_attributes: [:id, :prim_sec, :qual_quant, :survey, :survey_link, :experiment, :other_type, :other_description,                                            :confidential, :data_description, :scope_id],                          material_attributes: [:id, :mattype, :description, :scope_id],                          mentoring_attributes: [:id, :frequency, :description, :scope_id],                          funding_attributes: [:id,  :expenses, :honorarium, :financing, :currency, :size, :amount_expenses, :amount_honorarium,                                  :comment, :amount_principal_financing, :return_on_finance, :period_of_return, :expense_description, :amount_expenses_pennies, :amount_honorarium_pennies, :amount_principal_financing_pennies,                                                :amount_expenses_currency, :scope_id],                          participant_attributes: [:id,  :title, :description, :location, :costs, :participation_cost,                                                    :eligibility, :eligibility_criteria, :currency, :participation_cost_pennies, :participation_cost_currency,                                                    :location_specific ],                          group_research_attributes: [:id, :number_of_group_members, :scope_id],                          ethic_attributes: [:id, :obtained, :date_expected, :ethics_comment, :ethics_policy_link, :scope_id],                          result_attributes: [:id, :report, :standard_licence, :bespoke_licence, :option, :assignment, :other_outcome,                                              :consulting, :link_to_bespoke_licence, :description],                          disclosure_attributes: [:id, :allusers, :publicity, :limitedorganisation, :limitedindustry, :limiteduser, :approveddisclosure],                          backgroundip_attributes: [:id, :scope_id, :copyright, :design, :patent, :trademark, :geographical_indication,                                                    :trade_secret, :other, :identifier_copyright, :identifier_design, :identifier_patent,                                                    :identifier_trademark, :identifier_geographical_indication, :identifier_trade_secret,                                                    :identifier_other, :description, :registered_owner, :unregistered_interest, :conditions,                                                    :pbr, :identifier_pbr ],                           finalise_attributes: [:id, :draft, :reminder, :reminder_date, :finalised_at, :scope_id]                           ]       )       end 

the error message says:

no route matches [post] "/projects/70/project_questions/new" 

i don't know make route or how make route new. thought part of automated process when generate scaffolding. can see has gone wrong?

i found user on has problems nested routes. changed controller show action follows:

def show   @user = user.find(params[:user_id])   @album = @user.albums.find(params[:id])   @photo = @album.photos.build end 

at moment, show action in project questions empty. however, belongs projects thought cover it. there series of steps follow make nested controller work?

thank you

no route matches [post] "/projects/70/project_questions/new"

you have nested routes defined,so should this

<%= simple_form_for [@project, @project_question] |f| %> 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -