You are here: Forums Ask a Rails expert how to write in model...
Posted in Forums : Ask a Rails expert
Authority 12
Posting Rating 3
Sign in to rate this post
|
hi i am a beginner for rails how to write this in a model and access in a controller |
Authority 62
Posting Rating 100
Sign in to rate this post
|
Use a plugin like attachment_fu or Paperclip. I prefer attachment_fu if a model has an undetermined number of attachments (e.g. a photo album has many photos) and Paperclip if I know that there’s only a certain number of attachments (e.g. a user has one avatar). |
Authority 25
Posting Rating 0
Sign in to rate this post
|
I wrote a small step by step tutorial on setting up attachment_fu with image science: The post also has a link to a free chapter from the advanced rails recipes book which will answer your attachment_fu questions for sure. - Johannes |
Authority 0
Posting Rating 0
Sign in to rate this post
|
You can use file_column plugin. nstalling is pretty straightfoward, just like the majority of Rails plugins: script/plugin install http://opensvn.csie.org/rails_file_column/plugins/file_column/trunk The first thing we need is to tell our model which column to use: class Blog < ActiveRecord::Base
file_column :image Now, if we want to include a upload mechanism in our form, we need to include some code like this: <%= file_column_field “blog”, “image” %> <%= image_tag url_for_file_column(“blog”, “image”) %> We can extend things further, like for instance, I may want to upload only “jpg” and “gif” images and I want them to have a certain size: class Blog < ActiveRecord::Base file_column :image
Using R-magick for resizing of images class Blog < ActiveRecord::Base file_column :image, :store_dir => “public/images/my_stupid_place_to_keep_images_uploaded”,
:magick => {:versions => {
:thumb => {:crop => “1:1”, :size => “86×87!”, :name => “peq”},
:normal => {:crop => “1:1”, :size => “289×258!”, :name=>”med”}
}
} |
Authority 62
Posting Rating 95
Sign in to rate this post
|
If all you need is file upload, you can do that in your model. http://gist.github.com/9323 If you need image magic stuff, go with paperclip, attachment fu etc. |
Ask a Rails expert : json gem error
Ask a Rails expert : Problem with break
Ask a Rails expert : activesupport string first method error
Ask a Rails expert : url_for broken ?
Ask a Rails expert : map.routes.rb pls help
Ask a Rails expert : how to h tag in controller
Ask a Rails expert : Problem with Restful routing and partial form
Ask a Rails expert : will_paginate, search and ajax
Ask a Rails expert : Mass Deletes in Admin Section