« Newer Snippets
Older Snippets »
3 total  XML / RSS feed 

Upload Image To Database

// Code To Upload an image to a database and then update its contents.

# Create an ew classified and attach an image with it.
def create
  image_types = ["image/jpeg", "image/pjpeg", "image/gif","image/png", "image/x-png"]
  @categories = Category.find(:all)
  @classified = Classified.new(params[:classified])
  @classified.user = session[:user]
  unless params[:classified][:picture].blank?
    if (image_types.include?params[:classified][:picture].content_type.chomp)
      @classified.picture = params[:classified][:picture].read
    else
      @classified.errors.add(:picture,  "Photo doesn't seem to be JPG, GIF, or PNG. please ensure it is a valid image file.")
      render :action => 'new'
      return
    end
  end

  if @classified.save
    redirect_to :action => 'list'
  else 
    render :action => 'new'
  end
end


# Update Method So user can change the image associated with their classified
def update
  image_types = ["image/jpeg", "image/pjpeg", "image/gif", "image/png", "image/x-png"]
  @classified = Classified.find(params[:id])
  @categories = Category.find(:all)
  
  if @classified.update_attributes(params[:classified])
    unless params[:classified][:picture].blank?
      if (image_types.include?params[:classified][:picture].content_type.chomp)
        @classified.picture = params[:classified][:picture].read
      else
        @classified.errors.add(:picture, " doesn't seem to be JPG, GIF, or PNG. please ensure it is a valid image file.")
        render :action => 'edit'
        return
      end
    end
    
    flash[:notice] = 'Classified was successfully updated.'
    redirect_to :action => 'show', :id => @classified
  else
    render :action => 'edit'
  end
end

Change password in Sybase

// description of your code here

#check last pwd change

1> use master
2> go
1> select name, pwdate from syslogins where name = 'wat'
2> go
 name                           pwdate                     
 ------------------------------ -------------------------- 
 wat                              Jul  3 2006 12:54PM 

(1 row affected)

#change pwd

sp_password   caller_passwd, new_passwd   [,   login_name  ] 
 - caller_passwd: old pwd
 - new_passwd
 - login_name: use only if you want to change other users pwd

Creating a table with migrations when using has_and_belongs_to_many

You can find the information at http://api.rubyonrails.org under the "create_table" method. The short answer is this though,

create_table :table_name, :id => false do |t|

end


:id is the part you're looking for, it defaults to true, which creates the :id as an autoincrementing primary key, if you use migrations and want to create the join table, you don't want an "id" column, so use :id => false to override the create_table method and tell it you don't want that primary key.
« Newer Snippets
Older Snippets »
3 total  XML / RSS feed