2016-07-23 3 views
0

나는 작동하는 매우 기본적인 Photo and Comments 모델을 가지고 있으며 주석을 작성하는 데 사용되는 Cflags 모델을 가지고 있습니다. ... Heroku가에서 다음과 같은 오류가 나는 사진/show.html.erb보기를 방문 할 때 모델이 CflagsCflag를 호출되지 않습니다 당신은 오타가ActionView :: Template :: Error (초기화되지 않은 상수 ActionView :: CompiledTemplates :: Cflags

ActionView::Template::Error (uninitialized constant ActionView::CompiledTemplates::Cflags 

photos/show.html.erb 
. 
. 
<% @photo.comments.each do |comment| %> 
    <%= form_for([comment, Cflags.new]) do |f| %> 
    <%= f.hidden_field :user_id, value: current_user.id %> 
    <%= f.submit "Report Inappropiate" %> 
    <% end %> 
<% end %> 

resources :photos do 
    resources :comments do 
    resources :cflags 
    end 
end 

PhotosController 
def show 
    @photo = Photo.approved.find(params[:id]) 
end 

CommentsController 
def create 
    @photo = Photo.find(params[:photo_id]) 
    @comment = @photo.comments.build(comment_params) 
    @comment.save 
    respond_to do |format| 
    format.html { redirect_to :back } 
    format.js 
    end 
end 

class Cflag < ActiveRecord::Base 
    belongs_to :comment, counter_cache: true 
    belongs_to :user, counter_cache: true 
    validates :user_id, presence: true 
    validates :comment_id, presence: true 
    validates :user_id, uniqueness: { 
    scope: [:comment_id], 
    message: 'You can only flag a comment once. Thank you for your feedback.' 
    } 
    default_scope -> { order(created_at: :desc) } 
end 

class CflagsController < ApplicationController 
before_action :logged_in_user 

def new 
end 

def create 
    @comment = Comment.find(params[:comment_id]) 
    @cflag = @comment.cflags.build(cflag_params) 
    if @cflag.save 
     if @comment.cflags_count > 1 
     @comment.update_attribute(:approved, false) 
     flash[:success] = "Flag created! Comment ##{@comment.id} has been removed for review. Thank you for your feedback" 
     redirect_to :back 
     else  
     flash[:success] = "Flag created! Thank you for your feedback" 
     redirect_to :back 
     end 
    else 
     redirect_to :back, notice: @cflag.errors.full_messages 
    end  
    end  

    private 
    def cflag_params 
     params.require(:cflag).permit(:user_id, :comment_id).merge(user_id: current_user.id) 
    end 
end 

create_table "cflags", force: :cascade do |t| 
    t.integer "comment_id" 
    t.integer "user_id" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
end 

add_index "cflags", ["comment_id"], name: "index_cflags_on_comment_id" 
add_index "cflags", ["user_id"], name: "index_cflags_on_user_id" 

답변

0

로그이 변경 :

photos/show.html.erb 
. 
. 
<% @photo.comments.each do |comment| %> 
    <%= form_for([comment, Cflags.new]) do |f| %> 
    <%= f.hidden_field :user_id, value: current_user.id %> 
    <%= f.submit "Report Inappropiate" %> 
    <% end %> 
<% end %> 

로를 이

photos/show.html.erb 
. 
. 
<% @photo.comments.each do |comment| %> 
    <%= form_for([comment, Cflag.new]) do |f| %> 
    <%= f.hidden_field :user_id, value: current_user.id %> 
    <%= f.submit "Report Inappropiate" %> 
    <% end %> 
<% end %> 
관련 문제