ga-wdi-exercises / project2

[project]
1 stars 30 forks source link

Issue with creating a new pedal #914

Closed basssamurai closed 7 years ago

basssamurai commented 7 years ago

I tried creating a new pedal. I expected the app to create a new pedal. It threw an error instead. My repo link is https://github.com/basssamurai/Build-a-Pedalboard and my question is about lines 11-14 in pedals_controller.rb

image

aspittel commented 7 years ago

  <%= f.label :name %>
  <%= f.text_field :name %>

  <%= f.label :style %>
  <%= f.text_field :style %>

  <%= f.label :photo_url %>
  <%= f.text_field :photo_url %>

  <%= f.submit %>

<% end %>

The new pedal needs to have the parent pedalboard attached to it -- either with a select for that pedalboard or by nesting the URLs so the parent is in the form like so: https://git.generalassemb.ly/ga-wdi-lessons/rails-routing#form-helpers

basssamurai commented 7 years ago

Thanks Ali! So because the class Pedal ":belongs to" the class Pedalboard, there has to be a direct association with a specific pedalboard? What if I wanted any given pedal to be associated with any pedalboard? I know that is a many to many relationship. Would I need to nest my routes to accomplish this?

superbuggy commented 7 years ago

trying adding optional: true

class Pedal < ApplicationRecord
  belongs_to :pedalboard, optional: true
end

from http://guides.rubyonrails.org/association_basics.html...

If you set the :optional option to true, then the presence of the associated object won't be validated. By default, this option is set to false.
superbuggy commented 7 years ago

Closing for now!