Коя година сме ?
Helper code:
def current_year Time.now.strftime('%Y') end
View:
"...Всички права запазени <%= current_year %> ...."
ShareSnippets е публично хранилище за програмен код. Лесно можете да съберете собствена колекция от отрязъци от код, да ги систематизирате с етикети, ключови думи, и да ги споделите (или ако не искате, да ги запазите за себе си!)
Уеб Адрес: http://blog.jivkobg.com
Добавени отрязъци: 29
Проекти: 3
Линкове: 2
def current_year Time.now.strftime('%Y') end
"...Всички права запазени <%= current_year %> ...."
rails _1.2.6_ името_на_проекта
map.resources :news -> map.resources :news, :singular => :news_instance news_path() /news new_news_instance_path() /news/new news_instance_path(1) /news/1 edit_news_instance_path(1) /news/1;edit #edit <% form_for(@news, :url=> news_instance_path(@news)) do |f| %> ...... if @news.save format.html { redirect_to news_instance_path(@news) } ......
sudo gem install fastercsv
require 'rubygems' require 'fastercsv' FasterCSV.foreach('./imAreas.csv') do |row| e1 = row[0] e2 = row[2] e3 = row[3] ......... end
cd vendor/plugins svn export https://secure.near-time.com/svn/plugins/trunk/tiny_mce
rake tiny_mce:scripts:install
<%= javascript_include_tiny_mce_if_used %> <%= tiny_mce if using_tiny_mce? %>
class Admin::BaseController < ApplicationController layout 'admin' uses_tiny_mce(:options => {:theme => 'advanced', :browsers => %w{msie gecko}, :theme_advanced_toolbar_location => "top", :theme_advanced_toolbar_align => "left", :theme_advanced_resizing => true, :theme_advanced_resize_horizontal => false, :paste_auto_cleanup_on_paste => true, :theme_advanced_buttons1 => %w{formatselect fontselect fontsizeselect bold italic underline strikethrough separator justifyleft justifycenter justifyright indent outdent separator bullist numlist forecolor backcolor separator link unlink image undo redo}, :theme_advanced_buttons2 => [], :theme_advanced_buttons3 => [], :plugins => %w{contextmenu paste}}, :only => [:new, :edit, :show, :index]) .....
:integer :float :datetime :date :timestamp :time :text :string :binary :boolean
<%= link_to_unless request.env['HTTP_REFERER'].nil?, 'back', request.env['HTTP_REFERER']%>
<%= link_to 'back', request.env['HTTP_REFERER'] unless request.env['HTTP_REFERER'].nil?%>
require ‘gettext/rails’ class ApplicationController < ActionController::Base
require ‘gettext/rails’
.... begin ENV["RAILS_ENV"] = @config[:db_mode] require ‘config/boot.rb’ require ‘config/environment.rb’ # require ‘app/controllers/application.rb’ ....
http://manuals.rubyonrails.com/read/chapter/105
http://wiki.dreamhost.com/RubyGems
gem install -y radiant Bulk updating Gem source index for: http://gems.rubyforge.org Killed
rm -rf /home/USERNAME/.gems/source_cache
RailsFCGIHandler.process! nil, 10 class RailsFCGIHandler private def frao_handler(signal) dispatcher_log :info, "asked to terminate immediately" dispatcher_log :info, "frao handler working its magic!" restart_handler(signal) end alias_method :exit_now_handler, :frao_handler end
#!/usr/bin/env ruby require File.dirname(__FILE__) + "/../config/environment" require 'fcgi_handler' class RailsFCGIHandler private def frao_handler(signal) dispatcher_log :info, "asked to terminate immediately" dispatcher_log :info, "frao handler working its magic!" restart_handler(signal) end alias_method :exit_now_handler, :frao_handler end RailsFCGIHandler.process!
create_table :images do |t|
t.column :parent_id, :integer
t.column :content_type, :string
t.column :filename, :string
t.column :thumbnail, :string
t.column :size, :integer
t.column :width, :integer
t.column :height, :integer
t.column :user_id, :integer
t.column :asset_id, :integer
t.column :asset_type, :string
end
t.column :asset_id, :integer
t.column :asset_type, :string
class Image < ActiveRecord::Base belongs_to :asset, :polymorphic => true, :dependent => :destroy .....
class Link < ActiveRecord::Base has_one :image, :class_name => 'Image', :as => :asset, :dependent => :destroy ....
class LinksController < ApplicationController def new @link = Link.new end def create @link = Link.new(params[:link]) if !params[:image][:uploaded_data].blank? @image = Image.new(params[:image]) @link.image = @image end if @link.save flash[:notice] = 'Линка е добавен успешно !' redirect_to :action => 'list' else render :action => 'new' end end def edit @link = Link.find(params[:id]) @image = @link.image end def update @link = Link.find(params[:id]) @link.attributes = params[:link] if !params[:image][:uploaded_data].blank? @image = Image.new(params[:image]) @link.image = @image end if @link.update_attributes(params[:link]) flash[:notice] = 'Линка беше променен !' redirect_to :action => 'list' else render :action => 'edit' end end
has_attachment :content_type => :image, :storage => :file_system, :max_size => 200.kilobytes, :resize_to => '320x240>', :thumbnails => { :thumb => '100x100>' } def validate errors.add("empty", "Изберете снимка на проекта") unless self.filename unless self.filename == nil # Images should only be GIF, JPEG, or PNG [:content_type].each do |attr_name| enum = attachment_options[attr_name] unless enum.nil? || enum.include?(send(attr_name)) errors.add("type","Файла който сте избрал е различен от JPEG, PNG или GIF") end end # Images should be less than 5 MB [:size].each do |attr_name| enum = attachment_options[attr_name] unless enum.nil? || enum.include?(send(attr_name)) errors.add("size", "Файла който сте избрал е с големина по-голяма от максималната 200 KB") end end end end
<%= error_message_on 'image', 'empty' %> <%= error_message_on 'image', 'size' %> <%= error_message_on 'image', 'type' %>
has_attachment :content_type => :image, :storage => :file_system, :max_size => 100.kilobytes, :resize_to => '320x240>', :thumbnails => { :thumb => '100x100>' } validates_attachment :content_type => "Файла който сте избрал е различен от JPEG, PNG или GIF", :empty => 'Изберете файл', :size => "Файла който сте избрал е с големина по-голяма от максималната позволена големина от 100 KB"
RAILS_APP/vendor/plugins/attachment_fu/init.rb
Technoweenie::AttachmentFu::InstanceMethods.module_eval do protected def attachment_valid? if self.filename.nil? errors.add_to_base attachment_validation_options[:empty] return end [:content_type, :size].each do |option| if attachment_validation_options[option] && attachment_options[option] && !attachment_options[option].include?(self.send(option)) errors.add_to_base attachment_validation_options[option] end end end end Technoweenie::AttachmentFu::ClassMethods.module_eval do # Options: # * <tt>:empty</tt> - Base error message when no file is uploaded. Default is "No file uploaded" # * <tt>:content_type</tt> - Base error message when the uploaded file is not a valid content type. # * <tt>:size</tt> - Base error message when the uploaded file is not a valid size. # # Example: # validates_attachment :content_type => "The file you uploaded was not a JPEG, PNG or GIF", # :size => "The image you uploaded was larger than the maximum size of 10MB" def validates_attachment(options={}) options[:empty] ||= "No file uploaded" class_inheritable_accessor :attachment_validation_options self.attachment_validation_options = options validate :attachment_valid? end
path = "#{RAILS_ROOT}/public/myimages/"
records = YourModel.find :all
for record in records
begin
if !record.picture.empty?
YourMolelPicture.create(
:parent_id => record.id,
:file => File.open("#{path}#{record.picture}")
)
end
rescue
И какво се случва при грешка :)
end
svn remove log/* --force svn commit -m "removing all log files from subversion" svn propset svn:ignore "*.log" log/ --force svn update log/ svn commit -m "Ignoring all files in /log/ ending in .log" svn propset svn:ignore "*" tmp/sessions tmp/cache tmp/sockets svn commit -m "Ignoring all files in /tmp/" svn remove tmp/* svn propset svn:ignore "*" tmp/ svn update tmp/ svn commit -m "ignore tmp/ content from now"
validates_format_of :param, :with => /^[0-9]+$/i, :message =>'Param: може да бъде само....'
class ApplicationController < ActionController::Base ..... before_filter :set_default_content_type after_filter :set_default_content_type def set_default_content_type headers["Content-Type"] = "text/html; charset=utf-8" suppress(ActiveRecord::StatementInvalid) do ActiveRecord::Base.connection.execute 'SET NAMES UTF8' end end .....
adapter: mysql database: DATABASE username: root password: host: localhost encoding: UTF8