私は一日中Amazon s3でペーパークリップを動作させようとしてきましたが、かなり近づいています。
とはいえ、このエラーを回避するにはどうすればよいですか? 曲のモデルにバケツを含めたので、何を求めているのかわかりません。これが解決されたら、動作するはずです。
エラー:
ArgumentError in SongsController#create
missing required :bucket option
respond_to do |format|
if @song.save
format.html { redirect_to @song, notice: 'Song was successfully created.' }
format.json { render action: 'show', status: :created, location: @song }
else
song.rb
class Song < ActiveRecord::Base
acts_as_voteable
belongs_to :user
has_many :comments, :dependent => :destroy
has_many :genre_songs
has_many :genres, through: :genre_songs
has_attached_file :track,
:storage => :s3,
:path => '/:class/:attachment/:id_partition/:style/:filename',
:url => ":s3_domain_url",
:bucket => ENV['bucketname']
validates_attachment :track, :presence => true
validates_presence_of :url
validates :title, length: { minimum: 10 }
validates :url, length: { maximum: 300 }
def self.tagged_with(name)
Genre.find_by_name!(name).songs
end
def tag_list
genres.map(&:name).join(", ")
end
def tag_list=(names)
self.genres = names.split(",").map do |n|
Genre.where(name: n.strip).first_or_create!
end
end
end
ペーパークリップ.rb
# config/initializers/paperclip.rb
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'
production.rb と development.rb
config.paperclip_defaults = {
:storage => :s3,
:s3_credentials => {
:bucket => ENV['my bucketname'],
:access_key_id => ENV['my access key'],
:secret_access_key => ENV['my secret access key']
}
}
show.html.erb
<p id="notice"><%= notice %>
<p>
<%= @song.title %> | ( <%= @song.url %> )
<br />
<span class="subtext"><span class="votes_<%= @song.id %>"><%= pluralize(@song.votes.count, 'like') %>,</span>
posted <%= time_ago_in_words(@song.created_at) + " ago" %>
<small><span class="comments"></small> | <%= pluralize(@song.comments.size, 'comment') %></span></small><br /></span></span>
</p>
<p>
<%= audio_tag (@song.track.url), controls: "controls", alt: "Please use chrome, ie, or safari", preload: :auto %>
</p>
<p>Genres: <%= raw @song.genres.map(&:name).map { |t| link_to t, genre_path(t) }.join(', ') %></p>
<%#= link_to 'Show', song, class: "button small secondary" %>
<%= link_to('Edit', edit_song_path(@song), class: "button small secondary") if can? :update, @song %>
<%#= link_to 'Back', songs_path, class: "button small secondary" %>
<br /><br />
<%= render :partial => 'comments/form' %>
<div class="replies">
<% unless @song.comments.empty? %>
<h5><%= pluralize(@song.comments.size, 'comment') %></h5>
<br />
<% end %>
<% if @song.comments.empty? %>
<p>There are no comments...</p>
<% else %>
<div id="comments">
<% for comment in @song.comments %>
<div class="comment">
<strong><%= link_to_unless comment.site_url.blank?, h(comment.author_name), h(comment.site_url) %></strong>
<em>on <%= comment.created_at.strftime('%b %d, %Y at %H:%M') %></em>
<%=simple_format comment.content %><hr>
<p>
<%= link_to("Edit", edit_comment_path(comment)) if can? :update, @comment %>
<% end %>
<%= link_to("Destroy", comment, :method => :delete, :confirm => "Are you sure?") if can? :destroy, @comment %>
</p>
</div></div>
<% end %>
</div></div>
song_controller.rb
class SongsController < ApplicationController
before_filter :authenticate_user!, only: [:create ,:edit, :update, :destroy, :vote_for_song]
before_action :set_song, only: [:show, :edit, :update, :destroy, :vote_for_song]
def vote_for
@song = Song.find(params[:id])
current_user.vote_for(@song)
@song.plusminus = @song.votes_for
@song.save
respond_to do |format|
format.js { render 'update_votes' }
end
end
def vote_against
@song = Song.find(params[:id])
current_user.vote_against(@song)
respond_to do |format|
format.js { render 'update_votes' }
end
end
def new_songs
@songs = Song.order "id DESC"
end
# GET /Songs
# GET /Songs.json
def index
if params[:genre]
@songs = Song.tagged_with(params[:genre]).paginate(:page => params[:page], :per_page => 15)
else
@songs = Song.order('plusminus').paginate(:page => params[:page], :per_page => 15)
end
end
# GET /Songs/1
# GET /Songs/1.json
def show
@comment = Comment.new(song: @song)
end
# GET /Songs/new
def new
@song = Song.new
end
# GET /Songs/1/edit
def edit
end
# POST /Songs
# POST /Songs.json
def create
@song = Song.new(song_params)
respond_to do |format|
if @song.save
format.html { redirect_to @song, notice: 'Song was successfully created.' }
format.json { render action: 'show', status: :created, location: @song }
else
format.html { render action: 'new' }
format.json { render json: @song.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /Songs/1
# PATCH/PUT /Songs/1.json
def update
respond_to do |format|
if @song.update(song_params)
format.html { redirect_to @song, notice: 'Song was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @song.errors, status: :unprocessable_entity }
end
end
end
# Song /Songs/1
# Song /Songs/1.json
def destroy
@song.destroy
respond_to do |format|
format.html { redirect_to songs_url }
format.json { head :no_content }
end
end
private
def set_song
@song = Song.find(params[:id])
end
def song_params
params.require(:song).permit(:title, :artist, :url, :track, :user_id, :tag_list)
end
end