0
사용자가 로그인하여 목록을 만들 수있는 앱이 있습니다. 이것은 로컬 호스트에서 작동하지만 Heroku가에 난에 서명하고가 (#에 대한 정의되지 않은 메서드`USER_ID = ')레일 4 : 사용자 로그인 후 목록을 업로드 할 수 없습니다.
NoMethodError 충돌 목록을 제출 한 후 :
전체 오류를
Parameters: {"utf8"=>"✓", "authenticity_token"=>"B+y5VOvBRe+TgTEXP+2mbElYy2LqPShkeqxy+pXizHI=", "listing"=>{"name"=>"apples", "description"=>"bunch of apples", "price"=>"2.33", "quantity"=>"12", "company"=>"test", "image"=>#<ActionDispatch::Http::UploadedFile:0x007f3159693278 @tempfile=#<Tempfile:/tmp/RackMultipart20140722-2-7zodjh>, @original_filename="apples.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"listing[image]\"; filename=\"apples.jpg\"\r\nContent-Type: image/jpeg\r\n">}, "commit"=>"Create Listing"}
2014-07-22T16:23:35.323773+00:00 app[web.1]: Command :: file -b --mime '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-4vgehy.jpg'
2014-07-22T16:23:35.323967+00:00 app[web.1]: Command :: file -b --mime '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-4vgehy.jpg'
2014-07-22T16:23:35.595147+00:00 app[web.1]: Command :: identify -format %m '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]'
2014-07-22T16:23:35.775282+00:00 app[web.1]: Command :: convert '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]' -auto-orient -resize "50" '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu620140722-2-8o0hbb'
2014-07-22T16:23:35.595158+00:00 app[web.1]: Command :: identify -format %m '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]'
2014-07-22T16:23:35.775255+00:00 app[web.1]: Command :: convert '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]' -auto-orient -resize "50" '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu620140722-2-8o0hbb'
2014-07-22T16:23:36.165057+00:00 app[web.1]: Command :: file -b --mime '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu620140722-2-8o0hbb'
2014-07-22T16:23:36.165138+00:00 app[web.1]: Command :: file -b --mime '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu620140722-2-8o0hbb'
2014-07-22T16:23:36.258293+00:00 app[web.1]: Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]' 2>/dev/null
2014-07-22T16:23:36.258523+00:00 app[web.1]: Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]' 2>/dev/null
2014-07-22T16:23:36.424127+00:00 app[web.1]: Command :: identify -format %m '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]'
2014-07-22T16:23:36.424101+00:00 app[web.1]: Command :: identify -format %m '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]'
2014-07-22T16:23:36.588678+00:00 app[web.1]: Command :: convert '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]' -auto-orient -resize "100x100>" '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu620140722-2-jb4tv3'
2014-07-22T16:23:36.777832+00:00 app[web.1]: Command :: file -b --mime '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu620140722-2-jb4tv3'
2014-07-22T16:23:36.777843+00:00 app[web.1]: Command :: file -b --mime '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu620140722-2-jb4tv3'
2014-07-22T16:23:36.588555+00:00 app[web.1]: Command :: convert '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]' -auto-orient -resize "100x100>" '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu620140722-2-jb4tv3'
2014-07-22T16:23:36.863756+00:00 heroku[router]: at=info method=POST path="/listings" host=sincurudemo.herokuapp.com request_id=17e210ab-2955-418b-9dd8-0475a29b3271 fwd="185.30.24.132" dyno=web.1 connect=0 service=1830 status=500 bytes=28895
2014-07-22T16:23:36.856835+00:00 app[web.1]: Completed 500 Internal Server Error in 1618ms
2014-07-22T16:23:36.856688+00:00 app[web.1]: Completed 500 Internal Server Error in 1618ms
2014-07-22T16:23:36.861125+00:00 app[web.1]:
2014-07-22T16:23:36.861129+00:00 app[web.1]: NoMethodError (undefined method `user_id=' for #<Listing:0x007f3159698f20>):
2014-07-22T16:23:36.861322+00:00 app[web.1]: app/controllers/listings_controller.rb:36:in `create'
2014-07-22T16:23:36.861141+00:00 app[web.1]: app/controllers/listings_controller.rb:36:in `create'
2014-07-22T16:23:36.861142+00:00 app[web.1]:
2014-07-22T16:23:36.861144+00:00 app[web.1]:
2014-07-22T16:23:36.861317+00:00 app[web.1]:
2014-07-22T16:23:36.861320+00:00 app[web.1]: NoMethodError (undefined method `user_id=' for #<Listing:0x007f3159698f20>):
2014-07-22T16:23:36.861325+00:00 app[web.1]:
2014-07-22T16:23:36.861324+00:00 app[web.1]:
목록을 다음과 같이. controller.rb
class ListingsController < ApplicationController
before_action :set_listing, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, only: [:seller, :new, :create, :edit, :update, :destroy]
before_filter :check_user, only: [:edit, :update, :destroy]
# GET /listings
# GET /listings.json
def seller
@listings = Listing.where(user: current_user).order("created_at DESC")
end
def index
@listings = Listing.all.order("created_at DESC")
end
# GET /listings/1
# GET /listings/1.json
def show
end
# GET /listings/new
def new
@listing = Listing.new
end
# GET /listings/1/edit
def edit
end
# POST /listings
# POST /listings.json
def create
@listing = Listing.new(listing_params)
@listing.user_id = current_user.id
respond_to do |format|
if @listing.save
format.html { redirect_to @listing, notice: 'Listing was successfully created.' }
format.json { render action: 'show', status: :created, location: @listing }
else
format.html { render action: 'new' }
format.json { render json: @listing.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /listings/1
# PATCH/PUT /listings/1.json
def update
respond_to do |format|
if @listing.update(listing_params)
format.html { redirect_to @listing, notice: 'Listing was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @listing.errors, status: :unprocessable_entity }
end
end
end
# DELETE /listings/1
# DELETE /listings/1.json
def destroy
@listing.destroy
respond_to do |format|
format.html { redirect_to listings_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_listing
@listing = Listing.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def listing_params
params.require(:listing).permit(:name, :description, :price, :quantity, :company, :image)
end
def check_user
if current_user != @listing.user
redirect_to root_url, alert: 'Sorry, This listing belongs to someone else'
end
end
end
listing.rb
class Listing < ActiveRecord::Base
if Rails.env.development?
has_attached_file :image, :styles => { :small => "50x", :thumb => "100x100>" }, :default_url => "default.jpg"
validates_attachment_content_type :image, :content_type => %w(image/jpeg image/jpg image/png)
else
has_attached_file :image, :styles => { :small => "50x", :thumb => "100x100>" }, :default_url => "default.jpg",
:storage => :dropbox,
:dropbox_credentials => Rails.root.join("config/dropbox.yml"),
:path => ":style/:id_:filename"
end
validates_attachment_content_type :image, :content_type => %w(image/jpeg image/jpg image/png)
validates_attachment_presence :image
validates :name, :description, :price, presence: true
validates :price, numericality: { greater_than: 0 }
belongs_to :user
end
class AddUserIdToListings < ActiveRecord::Migration
def change
add_column :listings, :user_id, :integer
end
end
당신이 당신의'listings' 테이블에'user_id'이 있습니까
user_id
방법listing_params
에수정
당신은 추가해야 하는가? – Pavan
@Pavan이 뭔가있을 수 있습니다. Heroku에서 마이그레이션을 실행 했습니까? – pdoherty926
예 업데이트를 참조하십시오. – Neil