v3.2.1
不知道为什么“计数”出现为零并且索引不会呈现,因为“计数”在每个模型中都很好,直到我通过范围验证进行唯一性。
有什么建议么?
模型
Class FeatureIcon < ActiveRecord::Base
belongs_to :user
validates_presence_of :img_size, :feature_name, :image, :user_id
validates_uniqueness_of :img_size, :scope => :feature_name
//paperclip interpolates stuff....
end
控制器
before_filter :load_user
def index
@feature_icons = @user.feature_icons.all
@feature_icon = @user.feature_icons.new
respond_to do |format|
format.html # index.html.erb
format.json { render json: @feature_icons }
format.js
end
end
def create
@feature_icon = @user.feature_icons.new(params[:feature_icon])
respond_to do |format|
if @feature_icon.save
format.html { redirect_to user_feature_icons_url, notice: 'successfully created.' }
format.json { render json: @feature_icon, status: :created, location: @feature_icon }
format.js
else
format.html { render action: "index" }
format.json { render json: @feature_icon.errors, status: :unprocessable_entity }
end
end
end
错误
NoMethodError in Feature_icons#create
undefined method `count' for nil:NilClass
Extracted source (around line #7):
6: <div class="count">
7: <div id="count" class="feed-count"><%= @feature_icons.count %></div>
8: </div>