I am a newbie in ruby on rails it's also my first ruby application. The
problem is database relation I am trying to make relation within two
tables and the same procedure are working properly in another relation
but here it's showing an error.
The error is:
'undefined method `create_applied_jobs' for nil:NilClass'
Here are my codes:
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 %>
--
Posted via
http://www.ruby-forum.com/.