Posts mit dem Label install werden angezeigt. Alle Posts anzeigen
Posts mit dem Label install werden angezeigt. Alle Posts anzeigen

Donnerstag, 22. Mai 2008

Traps falls installing things, addons and packages

It turns out that using preconfigured binaries and packages are waste of time.
For example. i install ruby using:

useraccount> pfexec pkg install ruby-dev

The package was compiled on the SUN cc compiler - which is fine, but.....
the setup.rb file of the ruby system has all the environment variables set from the machine it was compiled on - and not mine. Editing that file by hand to adapt the environment to my machine is a night mare.

The RMagick gem and for that matter the source code both look at the environment in the setup.rb file and because nothing in there is relevant to my machine the install fails.

useraccount> pfexec uninstall ruby-dev
useraccount> su
superuseraccount> pfexec rm -r /ruby

So the only way to do this properly is uninstall the ruby pkg, get rid of the installation from my file system, down load the source and compile it again.

useraccount> cd /export/home/tmp
useraccount>pfexec wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p110.tar.bz2
useraccount>pfexec bunzip2 -dc ruby-1.8.6-p110.tar.bz2 | tar xf -

Using ruby setup.rb

This is a great place to read about it

Dienstag, 20. Mai 2008

Install plugin attachement_fu

ruby script/plugin install attachment_fu

create a scaffold
=============
ruby script/generate scaffold Photo parent_id:integer content_type:string filename:string size:integer width:integer height:integer

photo migration
=============

class CreatePhotos < default =""> ""
t.string :content_type, :default => ""
t.string :filename, :default => ""
t.integer :size, :default => 0
t.integer :width, :default => 0
t.integer :height, :default => 0

t.timestamps
end
photo=Photo.new(:content_type=>" image/jpeg", :filename=>"default_avatar_1.jpg", :size => 4.kilobytes, :width=>114, :height=>150)
photo.save
photo=Photo.new(:parent_id => photo.id, :content_type=>" image/jpeg", :filename=>"default_avatar_1_thumb.jpg", :thumbnail => "thumb", :size => 4.kilobytes, :width=>24, :height=>32)
photo.save
end

def self.down
drop_table :photos
end
end

photo.rb
=======

class Photo < ActiveRecord::Base
has_one :profile

has_attachment :content_type => :image,
:storage => :file_system,
:size => 1.kilobyte..20.kilobytes,
:resize_to => '150x150'
# :thumbnails => { :thumb => '32x32' }

# validates_numericality_of :size, :only_integer => true, :greater_than => 1.kilobyte, :less_than => 20.kilobytes, :message => "File size out of range"
#TODO get the regex for content type
#validates_format_of :content_type, :with => :image, :message => "Picture is not an image"
validates_presence_of :width, :on => :update, :message => "width missing"
validates_presence_of :height, :on => :update, :messgae => "height missing"
validates_presence_of :filename, :on => :update, :message => "File name missing"

#attr_accessible :filename, :content_type, :width, :height, :size

end

###########################################################################

attachment-fu
=============

attachment_fu is a plugin by Rick Olson (aka technoweenie ) and is the successor to acts_as_attachment. To get a basic run-through of its capabilities, check out Mike Clark's tutorial .


attachment_fu functionality
===========================

attachment_fu facilitates file uploads in Ruby on Rails. There are a few storage options for the actual file data, but the plugin always at a minimum stores metadata for each file in the database.

There are three storage options for files uploaded through attachment_fu:
File system
Database file
Amazon S3

Each method of storage many options associated with it that will be covered in the following section. Something to note, however, is that the Amazon S3 storage requires you to modify config/amazon_s3.yml and the Database file storage requires an extra table.


attachment_fu models
====================

For all three of these storage options a table of metadata is required. This table will contain information about the file (hence the 'meta') and its location. This table has no restrictions on naming, unlike the extra table required for database storage, which must have a table name of db_files (and by convention a model of DbFile).

In the model there are two methods made available by this plugins: has_attachment and validates_as_attachment.

has_attachment(options = {})
This method accepts the options in a hash:
:content_type # Allowed content types.
# Allows all by default. Use :image to allow all standard image types.
:min_size # Minimum size allowed.
# 1 byte is the default.
:max_size # Maximum size allowed.
# 1.megabyte is the default.
:size # Range of sizes allowed.
# (1..1.megabyte) is the default. This overrides the :min_size and :max_size options.
:resize_to # Used by RMagick to resize images.
# Pass either an array of width/height, or a geometry string.
:thumbnails # Specifies a set of thumbnails to generate.
# This accepts a hash of filename suffixes and RMagick resizing options.
# This option need only be included if you want thumbnailing.
:thumbnail_class # Set which model class to use for thumbnails.
# This current attachment class is used by default.
:path_prefix # path to store the uploaded files.
# Uses public/#{table_name} by default for the filesystem, and just #{table_name} for the S3 backend.
# Setting this sets the :storage to :file_system.
:storage # Specifies the storage system to use..
# Defaults to :db_file. Options are :file_system, :db_file, and :s3.
:processor # Sets the image processor to use for resizing of the attached image.
# Options include ImageScience, Rmagick, and MiniMagick. Default is whatever is installed.


Examples:
has_attachment :max_size => 1.kilobyte
has_attachment :size => 1.megabyte..2.megabytes
has_attachment :content_type => 'application/pdf'
has_attachment :content_type => ['application/pdf', 'application/msword', 'text/plain']
has_attachment :content_type => :image, :resize_to => [50,50]
has_attachment :content_type => ['application/pdf', :image], :resize_to => 'x50'
has_attachment :thumbnails => { :thumb => [50, 50], :geometry => 'x50' }
has_attachment :storage => :file_system, :path_prefix => 'public/files'
has_attachment :storage => :file_system, :path_prefix => 'public/files',
:content_type => :image, :resize_to => [50,50]
has_attachment :storage => :file_system, :path_prefix => 'public/files',
:thumbnails => { :thumb => [50, 50], :geometry => 'x50' }
has_attachment :storage => :s3

validates_as_attachment
This method prevents files outside of the valid range (:min_size to :max_size, or the :size range) from being saved. It does not however, halt the upload of such files. They will be uploaded into memory regardless of size before validation.

Example:
validates_as_attachment


attachment_fu migrations
========================

Fields for attachment_fu metadata tables...
in general:
size, :integer # file size in bytes
content_type, :string # mime type, ex: application/mp3
filename, :string # sanitized filename
that reference images:
height, :integer # in pixels
width, :integer # in pixels
that reference images that will be thumbnailed:
parent_id, :integer # id of parent image (on the same table, a self-referencing foreign-key).
# Only populated if the current object is a thumbnail.
thumbnail, :string # the 'type' of thumbnail this attachment record describes.
# Only populated if the current object is a thumbnail.
# Usage:
# [ In Model 'Avatar' ]
# has_attachment :content_type => :image,
# :storage => :file_system,
# :max_size => 500.kilobytes,
# :resize_to => '320x200>',
# :thumbnails => { :small => '10x10>',
# :thumb => '100x100>' }
# [ Elsewhere ]
# @user.avatar.thumbnails.first.thumbnail #=> 'small'
that reference files stored in the database (:db_file):
db_file_id, :integer # id of the file in the database (foreign key)

Field for attachment_fu db_files table:
data, :binary # binary file data, for use in database file storage


attachment_fu views
===================

There are two main views tasks that will be directly affected by attachment_fu: upload forms and displaying uploaded images.

There are two parts of the upload form that differ from typical usage.
1. Include ':multipart => true' in the html options of the form_for tag.
Example:
<% form_for(:attachment_metadata, :url => { :action => "create" }, :html => { :multipart => true }) do |form| %>

2. Use the file_field helper with :uploaded_data as the field name.
Example:
<%= form.file_field :uploaded_data %>

Displaying uploaded images is made easy by the public_filename method of the ActiveRecord attachment objects using file system and s3 storage.

public_filename(thumbnail = nil)
Returns the public path to the file. If a thumbnail prefix is specified it will return the public file path to the corresponding thumbnail.
Examples:
attachment_obj.public_filename #=> /attachments/2/file.jpg
attachment_obj.public_filename(:thumb) #=> /attachments/2/file_thumb.jpg
attachment_obj.public_filename(:small) #=> /attachments/2/file_small.jpg

When serving files from database storage, doing more than simply downloading the file is beyond the scope of this document.


attachment_fu controllers
=========================

There are two considerations to take into account when using attachment_fu in controllers.

The first is when the files have no publicly accessible path and need to be downloaded through an action.

Example:
def readme
send_file '/path/to/readme.txt', :type => 'plain/text', :disposition => 'inline'
end

See the possible values for send_file for reference.


The second is when saving the file when submitted from a form.
Example in view:
<%= form.file_field :attachable, :uploaded_data %>

Example in controller:
def create
@attachable_file = AttachmentMetadataModel.new(params[:attachable])
if @attachable_file.save
flash[:notice] = 'Attachment was successfully created.'
redirect_to attachable_url(@attachable_file)
else
render :action => :new
end
end

setting up svn with a rails 2.0.2 project

more or less got this from here.

Go to the directory you want to set up the rails project in.

then

useraccount> mkdir svn_setup
useraccount> cd svn_setup
useraccount> rails project_name -d mysql
useraccount> mv project_name trunk
useraccount> mkdir tags
useraccount> mkdir branches
useraccount> cd trunk
useraccount> rm -r tmp/*
useraccount> rm -r log/*
useraccount> mv config/database.yml database_example.yml
useraccount> cd ..
useraccount> svn import . url_of_svn_repository_space_on_assembla -m "initial repository import" --user name_of_assembla_user

now the project should be in the svn repository in assembla

now checkout the project from the repository in assembla to your localhost

useraccount> cd
useraccount> svn co url_of_svn_repository_space_on_assembla/trunk project_name

project_name is now what you can work on and thus you can get rid of the svn_setup folder you made earlier.

useraccount> rm -r svn_setup

now for the last bits and bobs.

useraccount> cd project_name
useraccount> cp /config/database_example.yml database.yml

useraccount> svn propset svn:ignore database.yml config/
useraccount> svn propset svn:ignore "*" log/
useraccount> svn propset svn:ignore "*" tmp/

Installing svn repository space on assembla

I would rather emulate what really might happen with a proper svn than use my local file system for a svn repository so sign up to assembla.com and get some svn space.

under the tab 'Trac/SVN' you will get the url of the SVN repository space.

DO NOT install AMP developers environment

Installing the reconfigured AMP environment for opensolaris caused me a lot of problems: machine not shutting down properly. not being able to shutdown via GNOME, not unmount startd properly and not getting any Internet when the machine boots up after a shutdown, which is not a shutdown but a restart instead.

Installing Mysql

as a normal user

useraccount>pexec pkg install SUNWmysql5

This installs mysql in /usr/mysql

Then change to su root and change the owner and groups of the files in etc and var as follows.

root>chown -R mysql:mysql /etc/mysql
root>chown -R mysql:mysql /var/mysql

also see docs

Installing Rails

as normal user (gems was installed with ruby).

useraccount>pfexec gem install rails --include-dependencies

Rails should now be in /usr/ruby/1.8

installing Ruby

Do as normal user account.

useraccount> pfexec pkg install ruby-dev

ruby should now be in /usr/ruby