开发者

Rails 3 & Paperclip - a problem with upload

I am trying to change a开发者_如何转开发 way of upload images on my page from my own upload to paperclip. I installed paperclip and tried to do following:

to table photos I added these columns:

| photo_file_name | varchar(255)

| photo_content_type | varchar(255)

| photo_file_size | int(11)

| photo_updated_at | datetime

Then to model photo.rb:

has_attached_file :photo, :styles => { :thumb=> "65x65#", :small => "500x500>" }

In my view I have:

<%= form_tag({ :controller => 'photos', :action => 'upload_it' }, { :multipart => true }) do %>                        
    <p>
        <%= file_field 'photo', 'photo'%>
    </p>
    <p>
        <label for="album">Select album</label> : 
        <%= select("post", "album_id", Album.where("account_id = ?", session[:user_id]).collect {|p| [ p.name, p.id ] }, {:include_blank => 'None'}) %>
    </p>    <p>
        <%= submit_tag "Upload" %>
    </p>
<% end %>

And in controller

  if defined? params[:photo][:photo]
      @qimg = Photo.new(:album_id => params[:post][:album_id],
                        :name => params[:photo][:photo]
                        )

  end

But this not works me... I am not sure, what everything is needed to set. And how can I get information like size of image, content_type etc?

Is something important, what I forget?

Thank you so much, M.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜