我遇到的问题比我能解决的还要严重。 我尝试更新对象但没有成功。 Rails调用“编辑”方法但从不调用“更新”方法。
这是我的控制者:
class JobsController < ApplicationController
def new
@job = Job.create(company_id: current_user.recruiter.company.id)
redirect_to edit_job_url(@job)
end
def edit
@job = Job.find(params[:id])
session[:edit_job_id] = @job.id
end
def update
@job = Job.find(params[:id])
@job.update_attributes(job_params)
if @job.save
redirect_to @job
else
render 'edit'
end
end
private
def job_params
params.require(:job).permit!.merge(company_id: current_user.recruiter.company.id)
end
end
这是我的编辑视图:
<%= form_for @job do |f| %>
......
<p>
<%= f.submit 'Ajouter' %>
</p>
<% end %>
有没有人可以给我建议?提前谢谢。
修改
这是我的路线:
mount Bootsy::Engine => '/bootsy', as: 'bootsy'
root 'static_pages#home'
devise_for :users, controllers: { registrations: 'users/registrations', :omniauth_callbacks => "users/omniauth_callbacks" }
resources :companies
resources :jobs
resources :candidates
resources :addresses
resources :job_languages, only: [:create, :update, :destroy]
resources :job_skills, only: [:create, :update, :destroy]
resources :job_study_types, only: [:create, :destroy]
resources :job_certifications, only: [:create, :destroy]
resources :candidate_languages, only: [:create, :update, :destroy]
resources :candidate_experiences, only: [:create, :edit, :update, :destroy]
resources :candidate_studies, only: [:create, :edit, :update, :destroy]
resources :candidate_skills, only: [:create, :edit, :update, :destroy]
resources :candidate_trainings, only: [:create, :edit, :update, :destroy]
嵌套表格:
<form>
<input type="text" data-model="DataSkill" id="live_data_skill_id" class="live_data_search"/>
<input type="hidden" id="data_skill_id"/>
<select id="data_skill_level">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
Expérience :
<input type="text" id="data_skill_start_year"/>
<input type="text" id="data_skill_end_year"/>
<input type="hidden" id="old_skill_id"/>
<a href="#" class="btn" id="add_data_skill">Enregistrer</a>
<form>
<select id="data_language_id">
<option value=""></option>
<%= DataLanguage.ordered.each do |lang| %>
<option value="<%= lang.id %>"><%= lang.name %></option>
<% end %>
</select>
<select id="data_language_level">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<input type="hidden" id="old_language_id"/>
<a href="#" class="btn" id="add_data_language" data-url="job_languages">Enregistrer</a>