Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 无法编辑(更新嵌套模型rails 4_Ruby On Rails_Forms_Ruby On Rails 4_Nested Attributes - Fatal编程技术网

Ruby on rails 无法编辑(更新嵌套模型rails 4

Ruby on rails 无法编辑(更新嵌套模型rails 4,ruby-on-rails,forms,ruby-on-rails-4,nested-attributes,Ruby On Rails,Forms,Ruby On Rails 4,Nested Attributes,我正在rails 4中构建嵌套表单。我的每件事都按预期工作,但当我尝试编辑页面时,它只在此处编辑父元素项目。子模型问题元素甚至不会在编辑模式下显示 my_form.html.erb as <%= nested_form_for (@project) do |f| %> <% if @project.errors.any? %> <div id="error_explanation"> <h2><%= plura

我正在rails 4中构建嵌套表单。我的每件事都按预期工作,但当我尝试编辑页面时,它只在此处编辑父元素项目。子模型问题元素甚至不会在编辑模式下显示

my_form.html.erb as

    <%= nested_form_for (@project) do |f| %>
    <% if @project.errors.any? %>
    <div id="error_explanation">
    <h2><%= pluralize(@project.errors.count, "error") %> prohibited this project from being saved:</h2>

    <ul>
    <% @project.errors.full_messages.each do |message| %>
      <li><%= message %></li>
     <% end %>
     </ul>
     </div>
    <% end %>

    <div class="field">
    <%= f.label :name %><br>
    <%= f.text_field :name %>
    </div>

    <%= f.fields_for :questions do |builder| %>
    <%= render "question_fields", :f => builder %>
                    <p><%= f.link_to_add "Add a questions",:questions %></p>
    <% end %>

    <div class="actions">
    <%= f.submit %>
    </div>
    <% end %>
问题.rb

      class Question < ActiveRecord::Base

       belongs_to :project

       end
结束

我用嵌套的宝石 请帮我摆脱这个错误

问题:-

      def question_params
      params.require(:question).permit(:id, :project_id, :subject, :content)
      end
项目管理主任

      def new
      @project = Project.new
       3.times do
       question = @project.questions.build
        end
      def project_params
      params.require(:project).permit(:name,questions_attributes: [:id,:project_id,:subject,:content])

      end

        def create
        @project = Project.new(project_params)

        respond_to do |format|
        if @project.save
        format.html { redirect_to @project, notice: 'Project was successfully created.' }
         format.json { render :show, status: :created, location: @project }
        else
         format.html { render :new }
        format.json { render json: @project.errors, status: :unprocessable_entity }
       end
      end
     before_action :set_project, only: [:show, :edit, :update, :destroy]


  def edit
   @question = Question.find_by_project_id(params[:id])
  end

    # POST /projects
    # POST /projects.json
    def create
    @project = Project.new(project_params)

     respond_to do |format|
     if @project.save
       format.html { redirect_to @project, notice: 'Project was successfully created.' }
       format.json { render :show, status: :created, location: @project }
     else
       format.html { render :new }
       format.json { render json: @project.errors, status: :unprocessable_entity }
      end
     end
    end

    def update
     respond_to do |format|
     if @project.update(project_params)
     format.html { redirect_to @project, notice: 'Project was successfully updated.' }
     format.json { render :show, status: :ok, location: @project }
      else
       format.html { render :edit }
       format.json { render json: @project.errors, status: :unprocessable_entity }
       end
      end
     end
私人的

# Use callbacks to share common setup or constraints between actions.

      def set_project
       @project = Project.find(params[:id])
    end

# Never trust parameters from the scary internet, only allow the white list through.
def project_params
 params.require(:project).permit(:name,questions_attributes: [:id,:project_id,:subject,:content,:_destroy])
 #params.require(:project).permit(:name, questions_attributes: [:id,:project_id,:subject,:content, :_destroy])

end

发布项目的编辑和更新方法。\u controller@Pavan查看我的编辑!!您可以创建父元素和子元素吗?@WaliAli是的,但在编辑页面上我可以编辑项目的元素,但问题的元素甚至不显示发布日志参数
     before_action :set_project, only: [:show, :edit, :update, :destroy]


  def edit
   @question = Question.find_by_project_id(params[:id])
  end

    # POST /projects
    # POST /projects.json
    def create
    @project = Project.new(project_params)

     respond_to do |format|
     if @project.save
       format.html { redirect_to @project, notice: 'Project was successfully created.' }
       format.json { render :show, status: :created, location: @project }
     else
       format.html { render :new }
       format.json { render json: @project.errors, status: :unprocessable_entity }
      end
     end
    end

    def update
     respond_to do |format|
     if @project.update(project_params)
     format.html { redirect_to @project, notice: 'Project was successfully updated.' }
     format.json { render :show, status: :ok, location: @project }
      else
       format.html { render :edit }
       format.json { render json: @project.errors, status: :unprocessable_entity }
       end
      end
     end
# Use callbacks to share common setup or constraints between actions.

      def set_project
       @project = Project.find(params[:id])
    end

# Never trust parameters from the scary internet, only allow the white list through.
def project_params
 params.require(:project).permit(:name,questions_attributes: [:id,:project_id,:subject,:content,:_destroy])
 #params.require(:project).permit(:name, questions_attributes: [:id,:project_id,:subject,:content, :_destroy])

end