Ruby on rails 实现模型的编辑/更新功能时出现问题

Ruby on rails 实现模型的编辑/更新功能时出现问题,ruby-on-rails,edit,controller-action,Ruby On Rails,Edit,Controller Action,当我尝试编辑作业模型的实例时,我尝试更新的属性设置为Nil 我尝试使用常规表单而不是简单表单作为助手,因为我不知道简单表单是否需要额外的信息,例如使用什么操作和方法,但它不起作用 edit.html.erb <h1>Edit Job:</h1> <br> <%= simple_form_for @job do |f| %> <%= f.input :title, label: "Job title" %> <%= f.in

当我尝试编辑作业模型的实例时,我尝试更新的属性设置为Nil

我尝试使用常规表单而不是简单表单作为助手,因为我不知道简单表单是否需要额外的信息,例如使用什么操作和方法,但它不起作用

edit.html.erb

<h1>Edit Job:</h1>
<br>
<%= simple_form_for @job do |f| %>
  <%= f.input :title, label: "Job title" %>
  <%= f.input :description, label: "Description" %>
  <%= f.button :submit %>
<% end %>
routes.rb

  resources :candidates
  resources :tenants, constraints: { subdomain: 'www' }, except: :index
  resources :jobs, path_names: { new: 'add' }
  get 'candidates/index'
  get 'candidates/new/:id' => 'candidates#new', :as => 'apply'
  get 'candidates/single/:id' => 'candidates#single', :as => 'view_candidate'
  get 'jobs/single/:id' => 'jobs#single', :as => 'single_job'
  get 'add-job' => 'jobs#new'
  get 'listings' => 'jobs#listings', :as => 'career_page'
  get 'listing/:id' => 'jobs#listing', :as => 'view_job'
  get 'welcome/index', constraints: { subdomain: 'www' }
  get 'dashboard' => 'tenants#dashboard', as: 'dashboard'
  constraints SubdomainConstraint do
    devise_for :users, path_names: { edit: 'account' }
    root 'tenants#dashboard'
  end

  root 'welcome#index'

没有错误,但是属性为零,并且在索引视图中显示URL而不是@job.title(因为它为零)

我相信表单数据被包装到
参数中的key
:job
中,因此
作业的属性需要被列入白名单

  def update
    @job = Job.find(params[:id])
    @job.update(job_params)

    if @job.save
      redirect_to jobs_path(@job)
    else
      render "edit"
    end
  end

Private
  def job_params
    params.require(:job).permit(:title, :description)
  end

@用户2570506可以自由投票,因为它帮助了您以及未来的SO搜索者。谢谢
  def update
    @job = Job.find(params[:id])
    @job.update(job_params)

    if @job.save
      redirect_to jobs_path(@job)
    else
      render "edit"
    end
  end

Private
  def job_params
    params.require(:job).permit(:title, :description)
  end