내가 레일에 매우 새로 온 GitHub의루비/레일 ActiveAdmin을 이미지 검사기 오류
에서 레일 4.1, 루비 2.0 및 ActiveAdmin을 사용하고 있습니다. 하지만 기본적으로 내가 원하는 것은 이미지 업로드를 허용하는 활성 관리 양식이며 img_url이라는 모델의 문자열에 URL을 저장하는 것입니다.
현재 img_url에는 아무 것도 저장하지 않으며 단지 NIL 만 저장합니다. 그러나이 양식을 사용하면 파일을 선택하고 계속 진행할 수 있습니다.
내 ActiveAdmin을 양식 :ActiveAdmin.register Product do
permit_params :name, :price, :description, :is_available,
:img_url
index do
column :img_url, :sortable => false do Product
"<img src='#img_url' alt='Product Logo' style='height:48px; display:block;
margin-left:auto;
margin-right:auto;'".html_safe
end
column :name
column :price do |item|
div :class => "price" do
number_to_currency item.price
end
end
column :description
column :is_available
actions
end
form :html => { :enctype => "multipart/form-data"} do |f|
f.inputs "Details" do
f.input :name
f.input :description, :as => :text
f.input :price
f.input :is_available
f.input :img_url, :label => 'Product Image', :as => :file
end
f.actions
end
end
내 제품 모델, 내 두 번째 문제로 날을 제공합니다 : 물론
class Product < ActiveRecord::Base
has_attached_file :img_url, :styles => { :thumb => "100x100" }
validates_attachment :img_url, :content_type => { :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"] }
end
, 내가 확인하기 위해 내용/유형을 확인하고 싶습니다 그것은 이미지입니다. 그러나 유효성을 검사 방법 내가 얻을 주석 :
"undefined method `img_url_content_type' for #<Product:0x000000060e4560>"
Parameters:
{"utf8"=>"✓",
"_method"=>"patch",
"authenticity_token"=>"5dtIAV866xUavdUQDFuL5/J0IIl6Un3l4Nu2sNOmy2c=",
"product"=>{"name"=>"Test",
"description"=>"Test Description",
"price"=>"5",
"is_available"=>"1",
"img_url"=>#<ActionDispatch::Http::UploadedFile:0x000000060ce378 @tempfile=#<Tempfile:/tmp/RackMultipart20141009-8450-2vnymd>,
@original_filename="100x100.gif",
@content_type="image/gif",
@headers="Content-Disposition: form-data; name=\"product[img_url]\"; filename=\"100x100.gif\"\r\nContent-Type: image/gif\r\n">},
"commit"=>"Update Product",
"id"=>"2"
또한 ActiveAdmin을 내 서버에서 파일을 삭제할 수 좋을 것입니다.
여기 이것은 내가 레일에서 수행 한 최초의 프로젝트, 그래서 더 이상 정보가 필요한 경우 바로 알려 주시기도
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.6'
# Use mysql as the database for Active Record
gem 'mysql2'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'oj'
gem 'oj_mimic_json'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
# ActiveAdmin
gem 'activeadmin', github: 'activeadmin'
gem 'devise'
gem 'paperclip', :git => "http://github.com/thoughtbot/paperclip.git"
, 내 gemfile입니다.
감사합니다.
UPDATE 나는 img_url가 저장되지 함께 문제였다 permit_params을 수정합니다.
또한 paperclip의 img_url_file_name에 대한 열/이전을 추가해야했습니다.
그러나, 지금 나는 내 자신의 질문에 대답하는거야