Rails - 报告方法不通过许可证varaibels

时间:2018-03-29 12:18:06

标签: ruby-on-rails

我有一种方法允许不同的字段在我的报告控制器中进行throguh。当我感觉到表格时,我收到了以下错误。

  

未定义的方法`permit' for" contentofreport ...":String你的意思是?打印

这是报告控制器。该方法是底部附近私有部分的查找报告方法。

    class ReportsController < ApplicationController

    before_action :find_patient
    before_action :find_report, only: [:show, :edit, :update, :destroy]
    before_action :require_login
    def new
        @reports = Report.new 
    end 

    def show 
    end

    def create
        @report = Report.new(report_params)
        @report.user_id = current_user.id
        @report.patient_id = @patient.id

        if @report.save
            redirect_to patient_path(@patient)
        else
            render 'new'
        end
    end

    def edit
    end

    def update
        if @report.update(report_params)
            redirect_to patient_path(@patient)
        else 
            render 'edit'
        end
    end

    def destroy
        @report.destroy
        redirect_to patient_path(@patient)
    end

    private

        def report_params
            params.require(:report).permit(:date, :report)
        end

        def find_patient
            @patient = Patient.find(params[:patient_id])
        end

        def find_report
            @report = Report.find(params[:id])
        end
end

报告模型

class Report < ActiveRecord::Base

    belongs_to :user
    belongs_to :patient
end

表单是

<%= simple_form_for([@patient, @patient.reports.build]) do |f| %>
    <div class="container">
        <div class="row">
            <div class="col-md-6">
                <div class="form-control">
                    <div class="form-group">
                        <%= f.label :date %>
                    </div>
                    <div class="form-group">
                        <%= date_field(:report, :date) %>
                    </div>
                    <div class="form-group">
                        <%= f.label :report %>
                    </div>

                     <div class="form-group">
                        <%= text_area_tag(:report, "", size: "24x6") %>
                    </div>
                    <center><%= f.button :submit, :class => 'button_one'  %></center>
                </div>
        </div>
    </div>
<% end %>

1 个答案:

答案 0 :(得分:0)

因为你在reports controller, 将控制器更改为,

def new
 @report = Report.new
end

and,

def report_params
    params.require(:report).permit(:date, :report)
end

<强>形式:

<%= simple_form_for @report do |f| %>
    <div class="container">
        <div class="row">
            <div class="col-md-6">
                <div class="form-control">
                    <div class="form-group">
                        <%= f.label :date %>
                    </div>
                    <div class="form-group">
                        <%= date_field(:report, :date) %>
                    </div>
                    <div class="form-group">
                        <%= f.label :report %>
                    </div>

                     <div class="form-group">
                        <%= text_area_tag(:report, "", size: "24x6") %>
                    </div>
                    <center><%= f.button :submit, :class => 'button_one'  %></center>
                </div>
        </div>
    </div>
<% end %>