kann nicht schreiben, unbekanntes Attribut `scrapbook_entry_id'

Versucht, fügen Sie Daten zu einer join-Tabelle der scrapbook_entries die has_one :Sammelalbum und has_one :Rezept.

:Rezept-und :Sammelalbum bereits vorhanden ist. Ich versuche, fügen Sie diese Verknüpfung mit der scrapbook_entries Tabelle.

form_for hinzufügen scrapbook_entries Tabelle:

<%= form_for(@scrapbook_entry, :url => scrapbook_entries_path(params[:id])) do |f| %>
  <%= render 'shared/error_messages', object: f.object %>
  <div class="field">
    <%=f.select(:scrapbook_id, current_user.scrapbooks.collect {|p| [ p.name, p.id ] },  {prompt: 'Select Scrapbook...'})%>
    <%= f.hidden_field :recipe_id, :value => @recipe.id %>
  </div>
  <%= f.submit "Save", class: "btn btn-large btn-primary" %>
<% end %>

scrapbook_entries_controller:

def create
    @recipe = Recipe.find(params[:scrapbook_entry][:recipe_id])
    @scrapbook = current_user.scrapbooks.find(params[:scrapbook_entry][:scrapbook_id])

    @entry = @scrapbook.scrapbook_entries.build(scrapbook: @scrapbook)
    if @entry.save
        flash[:success] = "Added '#{@recipe.name}' to scrapbook '#{@scrapbook.name}'"
    else
        flash[:error] = "Could not add to scrapbook"
    end
    redirect_to @recipe
end

Sammelalbum.rb

has_many :recipes, through: :scrapbook_entries
has_many :scrapbook_entries

Rezept.rb

has_many :scrapbooks, through: :scrapbook_entries

scrapbook_entry.rb

has_one :recipe
has_one :scrapbook

Auf dem Absenden des Formulars auf die Steuerung erhalte ich eine Fehlermeldung:

can't write unknown attribute `scrapbook_entry_id'

Kann mir jemand sagen was ich falsch mache?

Update:

schema.rb

 create_table "scrapbook_entries", force: true do |t|
   t.integer  "scrapbook_id"
   t.integer  "recipe_id"
   t.datetime "created_at"
   t.datetime "updated_at"
   t.integer  "user_id"
 end
  • können Sie fügen Sie den Parameter, den Sie erhalten, in Aktionen erstellen, die form der Entwicklung melden
InformationsquelleAutor MikeHolford | 2013-12-23
Schreibe einen Kommentar