On 23 January 2016 at 12:39, Mukto Mona <lists@ruby-forum.com> wrote:
> 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'
If you look more carefully at the stack trace (in the server window or
in log/development.log) you should be able to see which line of your
code caused the problem.
>
>
> 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])
I am assuming that it this line that has generated the error. The
error means that you have called create_applied_jobs on a variable
that is nil, so @current_user is nil. Perhaps you have not called
current_user, I don't see where you are calling current_user to set it
up. In fact I am not sure why you don't just have
current_user.create_applied_jobs(params[:applied_job])
though I have not looked in great detail at your code so there may be a reason.
Colin
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLsE5HTZOiTVL9WCOEtuchbKVBp0Jepcby00kbq%3DxUr3og%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment