在更正验证错误后,表单将不会处理。

时间:2016-06-09 19:44:46

标签: ruby-on-rails

我有一个表单,我正在解析字段的内容,然后在控制器中设置两个其他字段。

换句话说,如果employee_raw_name是[“Christopher Mendla”],我会删除[“”]并将名称分为第一个和最后一个。

除非验证失败,否则我会得到

NoMethodError in ObservationsController#create
undefined method `[]' for nil:NilClass

Rails.root: C:/Users/cmendla/RubymineProjects/employee_observations

Application Trace | Framework Trace | Full Trace
app/controllers/observations_controller.rb:243:in `create'
Request

Parameters:

{"utf8"=>"✓",
 "authenticity_token"=>"JGV9M89AoaTAmcjhKCQUw75S01lee6MJsHWniPssGt+uFucY3YXRzhyWdBCxKTZ6zwSPz/qvfCHhsWeDRDNr8w==",
 "observation"=>{"date(1i)"=>"2016",
 "date(2i)"=>"6",
 "date(3i)"=>"9",
 "status"=>"Sent to employee for acknowledgement",
 "performance"=>"Positive",
 "disciplinary_notice"=>"",
 "department_id"=>"",
 "observation"=>"asdasd",
 "comments"=>"asdasd",
 "discussed_with_employee"=>"0",
 "date_discussed"=>"2016-06-10"},
 "commit"=>"Create Observation"}

第243行位于employee_name = employee_name[2...-2]

以下的创建版本中
    def create
        @observation = Observation.new(observation_params)


    # ------------------------------------------------------------------------------------------
    # the following will take the employee_raw name and parse it into a first and last name. Then it will set up a user
    # for that name if a user does not already exist.

   '
          employee_name = @observation.employee_raw             # Employee_raw is from the listing from LDAP
          employee_name  = employee_name[2...-2]                # strip off the "[  and ]"
          employee_name = employee_name.split(' ')              # split into first and last names based on a space.
          # TODO - Account for initials and names such as Van, Von, La etc.
          employee_first_name = employee_name[0]                # grab the first name and populate the field
          employee_last_name= employee_name[1]                  # grab the last name and populate the field.
          $temp3 = '|' + employee_first_name + '|'

我放了一个<%= action_name%>在表格上,我可以看到是否有差异。当我第一次加载表单时,操作是“新”。如果存在验证错误,则操作为“创建”。我怀疑这是问题的根源,但我不知道如何解决它。我尝试将该块放入'if action_name!='create'`但这不起作用。

0 个答案:

没有答案