ruby - Uploading a pdf to rails using paperclip not working -
i using paperclip upload pdf's db. pdf isn't uploaded db, creates blank entry, so:
2.1.0 :001 > yearlyguide.last yearlyguide load (1.4ms) select "yearly_guides".* "yearly_guides" order "yearly_guides"."id" desc limit 1 => #<yearlyguide id: 2, pdf_file_name: nil, pdf_content_type: nil, pdf_file_size: nil, pdf_updated_at: nil, start: nil, end: nil, created_at: "2014-06-09 14:10:50", updated_at: "2014-06-09 14:10:50">
my controller looks this:
def new @yearguide = yearlyguide.new
end
def create @yearguide = yearlyguide.create if @yearguide.save redirect_to '/' else render 'new' end
end
and model this:
class yearlyguide < activerecord::base has_attached_file :pdf validates_attachment :pdf, content_type: { content_type: "application/pdf" } end
my new.html.erb this:
<%= bootstrap_form_for(@yearguide, layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10") |f| %>
<%= f.date_select :end %> <%= f.file_field :pdf, help: "ensure images minimum 400x400px" %> <%= f.submit "add event", class: "btn btn-primary" %>
why isn't file being uploaded? missing? there erros code?
rails 3
def create @yearguide = yearlyguide.new(params[:yearly_guide]) if @yearguide.save redirect_to '/' else render 'new' end end
rails 4
def create @yearguide = yearlyguide.new(yearly_guide_params) if @yearguide.save redirect_to '/' else render 'new' end end def yearly_guide_params params.require(:yearly_guide).permit(:pdf) end
in short you're using .create
passing no parameters, because you've got if @yearguide.save
want new. if want create sub in create in answer above - leaving params part.
Comments
Post a Comment