0
내 웹 앱에는 public_bundle has_many 카드와 public_bundle 카드가 있습니다. 나는이 연관성을 추가했지만, 새로운 공용 번들을 만들려고 할 때 public_bundle에 대해 정의되지 않은 메서드 'cards'를 말하는 nothemod 오류가 발생합니다.PublicBundlesController의 NoMethodError # show
모델 :
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
컨트롤러 :
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
보기 : 당신이 그런 식으로 새로운 @card
인스턴스 변수를 생성 할 때
<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>
오류 스택 추적을 추가하십시오. –
죄송합니다. @ArupRakshit이라는 용어에 익숙하지 않습니다. – nums