我是一名Ruby on Rails的新手,這也是我的第一個Ruby應用程序。問題是數據庫關係我試圖使關係在兩個表中,並且相同的過程在另一個關係中正常工作,但在這裏顯示錯誤。Rails數據庫表關係問題
的錯誤是:
未定義的方法`create_applied_jobs'的零:NilClass
這裏是我的代碼:
applied_job.rb
class AppliedJob < ActiveRecord::Base
belongs_to :jobseekers
end
jobseeker.rb
class Jobseeker < ActiveRecord::Base
has_one :applied_job
end
view_details_controller.rb
def create
params.permit!
if @applied_job = @current_user.create_applied_jobs(params[:applied_job])
flash[:notice] = "You have applied successfully"
render "viewDetails"
else
render "viewDetails"
flash[:warning] = "Please try agian"
end
end
sessions_helper.rb
def current_user
@current_user ||= Jobseeker.find_by(jobseeker_id: session[:user_id])
end
viewDetails.html.erb
<%= form_for :applied_job, url: viewDetails_path(@applied_job), action: :create, method: :post do |f| %>
<ul class="form-style-1">
<li><label>Preferred Joining Date<span class="required">*</span></label>
<%= f.text_field :preffered_joining_date, class: 'field-long', id: 'datepicker', placeholder: 'Preferred Joining Date'%>
</li>
<li>
<label>Expected Salary <span class="required">*</span></label>
<%= f.text_field :expected_salary, class: 'form-control', placeholder: 'Expected Salary'%>
</li>
<li>
<input type="submit" value="Submit" />
</li>
</ul>
<% end %>
我想將數據插入到applied_jobs表中,其中jobseeker_id是foreign_key。
任何人都可以幫助我確定哪裏有bug?
Mukto蒙娜麗莎,什麼是CURRENT_USER,是用戶表,發佈user.rb代碼以及 –
好的@RameshKumarThiyagarajan – Fameless
你在'jobseekers'表中有'jobseeker_id'嗎? – Pavan