In meiner Web App hat ein public_bundle has_many cards und eine card gehört zu einem public_bundle. Ich fügte die Assoziationen für dieses hinzu, aber wenn ich versuche, ein neues öffentliches Bündel zu schaffen, erhalte ich einen nothemod Fehler, der unbestimmte Methode "cards" für das public_bundle sagt.NoMethodError in PublicBundlesController # show
Modelle:
class User < ActiveRecord::Base
has_secure_password
has_many :cards, through: :public_bundles
has_many :cards, through: :bundles
has_many :bundles
has_many :public_bundles
end
class PublicBundle < ActiveRecord::Base
has_many :cards
belongs_to :user
end
class Card < ActiveRecord::Base
belongs_to :user
belongs_to :public_bundle
belongs_to :bundle
end
Controller:
class CardsController < ApplicationController
def new
@card = current_user.public_bundles.cards.new
end
def create
@card = current_user.public_bundles.cards.new(card_params)
if @card.save
redirect_to '/'
else
render @public_bundle
end
end
private
def card_params
params.require(:card).permit(:name, :description, :image)
end
class PublicBundlesController < ApplicationController
def show
@public_bundle = current_user.public_bundles.find(params[:id])
@public_bundle_edit = current_user.public_bundles.find(params[:id])
@card = current_user.public_bundles.cards.new
@cards = @public_bundle.cards.all
end
private
def public_bundle_params
params.require(:public_bundle).permit(:name)
end
Ausblick:
<div class="new-card">
<%= form_for @card do |x| %>
<%= x.text_field :name, :placeholder => " New Card Name", :style => "height:30px; width:530px; border:#ff4d4d solid; margin-top:14px; padding:5px; margin-left:14px; background-color:#eff5f5;" %>
<%= x.text_field :image, :placeholder => " New Card Image (Optional)", :style => "height:30px; width:530px; border:#ff4d4d solid; margin-top:14px; padding:5px; margin-left:14px; background-color:#eff5f5;" %>
<%= x.text_area :description, :placeholder => " New Card Description", :style => "height:30px; width:530px; border:#ff4d4d solid; margin-top:14px; padding:5px; margin-left:14px; background-color:#eff5f5;" %>
<%= x.submit "✔", :style => "height:40px; width:40px; margin-top:10px; border-radius:100%; font-size:20px; background-color:#cce0ff; cursor:pointer; margin-left:270px;" %>
<% end %>
</div>
den Fehler-Stack-Trace please. –
Es tut mir leid, ich bin nicht vertraut mit diesem Begriff @ArupRakshit – nums