0

I have two models, a profile model and a job model. A profile has_many jobs and a job belongs_to a profile. I am using the cacoon gem in order to create nested forms. In my application, someone creates a profile, and then they can add jobs. So, by the time they are making their first job, a profile is already created, a job is not, and the form data will go to the update action (since a profile already exists, even though no jobs do). The problem is, since there are no jobs yet, I am receiving the error:

param not found: profile

Here are the params I tried using:

def profile_params
      params.require(:profile).permit(:title, :category, :description, :state, :zip_code, :rate, jobs_attributes: [:firm, :position, :category, :description, :begin, :end, :_destroy])
end

I then switched to the following code as recommended from another stack overflow post:

def profile_params
      params.fetch(:profile, {}).permit(:title, :category, :description, :state, :zip_code, :rate, jobs_attributes: [:firm, :position, :category, :description, :begin, :end, :_destroy])
end

With the second profile_params (the one with fetch), the page will load with a successful flash message, but the job is not actually being created. I don't think the fetch is working. Any ideas on how to get this working? Thanks.

Philip7899
  • 4,599
  • 4
  • 55
  • 114
  • Are you sure params[:profile] does exist? Just to verify, log it (`Rails.logger.debug(params)`) and check your `development.log` file. – Michael Lynch Nov 01 '13 at 17:47
  • It exists because Im not having any problem making a profile. Its when it gets to the update action and no jobs exist. How do I log? I tried typing Rails.logger.debug(params) into the console but I don't think thats how I'm supposed to do it? Thanks for your help. – Philip7899 Nov 01 '13 at 17:49
  • you can put it right `profile_params` function, and whenever that function gets hit, it will print it out to your `development.log` file (or rather w.e environment you are running in). In your terminal window you can type `tail -f log/development.log` to open your log file and monitor it. – Michael Lynch Nov 01 '13 at 17:52
  • when i add the line Rails.logger.debug(params) to the end of the profile_params method, I get the following notice 'undefined method `stringify_keys' for true:TrueClass'. When I run ' tail -f log/development.log', I get: 'NoMethodError (undefined method `stringify_keys' for true:TrueClass): app/controllers/profiles_controller.rb:37:in `update' ' – Philip7899 Nov 01 '13 at 18:13
  • Add it before. When you make it the last line in the function, it is considered the return statement, and thats going to mess with your `update()` call. – Michael Lynch Nov 01 '13 at 18:23
  • The development.log file just printed a bunch of 'started get' statements. – Philip7899 Nov 01 '13 at 18:26
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/40391/discussion-between-michael-lynch-and-philip7899) – Michael Lynch Nov 01 '13 at 18:34

0 Answers0