background preloader

Ruby i RoR

Facebook Twitter

Ruby on Rails Screencasts - RailsCasts. Ruby on Rails Guides. ActiveRecord. Migrations can manage the evolution of a schema used by several physical databases.

ActiveRecord

It’s a solution to the common problem of adding a field to make a new feature work in your local database, but being unsure of how to push that change to other developers and to the production server. With migrations, you can describe the transformations in self-contained classes that can be checked into version control systems and executed against another database that might be one, two, or five versions behind. Example of a simple migration: class AddSsl < ActiveRecord::Migration def up add_column :accounts, :ssl_enabled, :boolean, default: true end def down remove_column :accounts, :ssl_enabled endend This migration will add a boolean flag to the accounts table and remove it if you’re backing out of the migration. Example of a more complex migration that also needs to initialize data: Available transformations Irreversible transformations Running migrations from within Rails Database support More examples.

Bootstrap. How To: Add sign_in, sign_out, and sign_up links to your layout template · plataformatec/devise Wiki. First add sign_in/out links, so the appropriate one will show up depending on whether the user is already signed in: # views/devise/menu/_login_items.html.erb<% if user_signed_in?

How To: Add sign_in, sign_out, and sign_up links to your layout template · plataformatec/devise Wiki

%><li><%= link_to('Logout', destroy_user_session_path, :method => :delete) %></li><% else %><li><%= link_to('Login', new_user_session_path) %></li><% end %> The :method => :delete part is required if you use the default HTTP method. To change it, you will need to tell Devise this: # config/initializers/devise.rb # The default HTTP method used to sign out a resource. You can then omit :method => :delete on all your sign_out links. Next come the sign_up links. .

# views/devise/menu/_registration_items.html.erb<% if user_signed_in? Then use these templates in your layouts/application.html.erb, like this: # layouts/application.html.erb<ul class="hmenu"><%= render 'devise/menu/registration_items' %><%= render 'devise/menu/login_items' %></ul><%= yield %> Add some menu styling to the CSS (here for a horizontal menu): Symbol (Ruby 2.0) Plataformatec/devise. Alexreisner/geocoder. Array (Ruby 2.0) String (Ruby 2.0) Str % arg → new_str click to toggle source Format—Uses str as a format specification, and returns the result of applying it to arg.

String (Ruby 2.0)

If the format specification contains more than one substitution, then arg must be an Array or Hash containing the values to be substituted. See Kernel::sprintf for details of the format string. static VALUE rb_str_format_m(VALUE str, VALUE arg) { volatile VALUE tmp = rb_check_array_type(arg); if (! NIL_P(tmp)) { return rb_str_format(RARRAY_LENINT(tmp), RARRAY_PTR(tmp), str); } return rb_str_format(1, &arg, str); } str * integer → new_str click to toggle source Copy — Returns a new String containing integer copies of the receiver. integer must be greater than or equal to 0. "Ho! Str + other_str → new_str click to toggle source Concatenation—Returns a new String containing other_str concatenated to str.

"Hello from " + self.to_s str << integer → str click to toggle source str << obj → str Append—Concatenates the given object to str. In this example ...