gem
gem install rubygems-update
#update_rubygems
gem update --system
gem install bundle
gem update
gem install rails
gem install rails --version 3.0.6
gem install rails --pre
gem install bcrypt-ruby
gem install unicorn
gem install mysql2
gem install omniauth
gem install rails_best_practices --source gemcutter.org
cd /usr/local/lib/ruby/gems/1.9.1/cache
cd /usr/lib/ruby/gems/1.8/cache
which gem
git
git clone git://github.com/locomotivecms/engine.git locomotive
git clone http://github.com/locomotivecms/engine.git locomotive
rails
rails plugin install open_id_authentication
rails plugin install https://github.com/rails/open_id_authentication.git
rails plugin install https://github.com/rails/open_id_authentication.git --force
rails new PROJECT -d mysql
rails server
rails server thin
rails s
rails s -p 3001
kill -9 $(cat /my/rails/app/tmp/pids/server.pid)
rails CODE samples
module ErrorMessagesHelper # Render error messages for the given objects. The :message and :header_message options are allowed. def error_messages_for(*objects) options = objects.extract_options! options[:header_message] ||= I18n.t(:"activerecord.errors.header", :default => "Invalid Fields") options[:message] ||= I18n.t(:"activerecord.errors.message", :default => "Correct the following errors and try again.") messages = objects.compact.map { |o| o.errors.full_messages }.flatten unless messages.empty? content_tag(:div, :class => "error_messages") do list_items = messages.map { |msg| content_tag(:li, msg) } content_tag(:h2, options[:header_message]) + content_tag(:p, options[:message]) + content_tag(:ul, list_items.join.html_safe) end end end module FormBuilderAdditions def error_messages(options = {}) @template.error_messages_for(@object, options) end end end ActionView::Helpers::FormBuilder.send(:include, ErrorMessagesHelper::FormBuilderAdditions)
rails CODE sample CHECK for REGULAR EXPRESSION
request.remote_addr !~ /^192.168.0.\d{1,3}$/
rails CODE sample XML
https://github.com/railstutorial/demo_app/blob/master/app/controllers/users_controller.rb
rails CODE sample JSON
--def index
----@authors = Author.where("name like ?", "%#{params[:q]}%")
----respond_to do |format|
------format.html
------format.json { render :json => @authors.map(&:attributes) }
----end
--end
rails v2
#rails _2.3.5_ bcms5 -d mysql -m http://browsercms.org/templates/demo.rb
#./script/server _2.3.2_ -p 80 -e development
rails generators
rails generate scaffold doc caption:string
rails generate migration add_user_ids_to_docs user_id:integer
rails g nifty:authentication --help
rails g nifty:authentication
rails g controller users new
rails g controller sessions new
rails g model user email:string password_hash:string password_salt:string
rails destroy model user
rails generate nifty:scaffold user username:string email:string password:string new edit
rails generate nifty:scaffold user_session --skip-model username:string password:string new destroy
rails generate nifty:scaffold user_session username:string password:string new destroy --skip-model
rails debug
rails dbconsole
rails console --sandbox
rails console
rails c
tail -f log/development.log
В контроллере:
def create
raise request.env["omniauth.auth"].to_yaml
render :text => request.env["omniauth.auth"].to_yaml
end
Вид:
<%= debug(@User) %>
RAILS_DEFAULT_LOGGER.info "\n\n\n\n\n\n\n\n"
RAILS_DEFAULT_LOGGER.info "#############################################"
rake
rake about
rake --tasks
rake tmp:clear
rake tmp:pids:clear # Clears all files in tmp/pids
rake tmp:sessions:clear # Clears all files in tmp/sessions
rake tmp:sockets:clear # Clears all files in tmp/sockets
rake -T db
rake db:drop
rake db:create
rake db:migrate
rake db:migrate RAILS_ENV=development
rake routes
rake -T open_id
rake open_id_authentication:db:create
??rake gems:freeze
??rake rails:freeze:gems
bundle
bundle install
bundle install --deployment
bundle install --no-deployment
bundle show thinking-sphinx
bundle pack
bundle install --path vendor/cache
bundle install --without development,test
bundle update
bundle exec rake db:create
bundle exec rake db:migrate
RAILS_ENV=production bundle exec rake db:migrate
bundle exec rake db:seed:first_user
RAILS_ENV=production bundle exec rake db:seed:first_user
bundle exec thin -d --pid log/thin.pid start
bundle exec thin --pid log/thin.pid stop
unicorn
unicorn_rails -h
unicorn_rails
unicorn_rails -p 3000
unicorn_rails -p 3000 -E production
mongrel
sudo gem install mongrel
sudo gem install mongrel_cluster
#sudo mongrel_rails cluster::configure -p {port} -e {environment} -a {address} -N {servers} --user {user} --group {group} -P {path-to-pid-file} -c {path-to-app}
sudo mongrel_rails cluster::configure -p 8000 -e production -a 127.0.0.0 -N 3 --user mongrel --group mongrel -P /var/www/apps/testapp/tmp/mongrel.pid -c /var/www/apps/testapp
sudo mongrel_rails cluster::start
rvm
https://rvm.beginrescueend.com/rvm/install/cd ~
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm) echo '[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
source .bash_profile
type rvm | head -1
rvm notes
/usr/local/rvm/bin/rvm install 1.9.2
/usr/local/rvm/bin/rvm install 1.8.7
/usr/local/rvm/bin/rvm use 1.9.2
/usr/local/rvm/bin/rvm use 1.9.1-p378
/usr/local/rvm/bin/rvm 1.8.7 --default
/usr/local/rvm/bin/rvm 1.9.2 --default
/usr/local/rvm/bin/rvm default
/usr/local/rvm/bin/rvm system
/usr/local/rvm/bin/rvm 1.8.7,1.9.2 gem install rails
/usr/local/rvm/bin/rvm benchmark hello_world.rb
http://adventuresincoding.com/2010/02/taking-the-helm-of-ruby-with-ruby-version-manager