name1({name2: :name3})
name1({:name2 => :name3})
# posts_controller.rb
class PostsController < ApplicationController
def index
@posts = Post.paginate(page: params[:page], per_page: 3)
respond_to do |format|
format.html
format.js
end
end
end
# index.html
<div class="page-header">
<h1>My posts</h1>
</div>
<div id="my-posts">
<%= render @posts %>
</div>
<div id="more_posts">
<%= link_to "More posts...", posts_index_url(page: @posts.next_page), remote: true %>
</div>
# index.js.erb
$("#my-posts").append('<%= escape_javascript render(@posts)%>');
$("#more_posts").html('<%= escape_javascript(link_to("More posts...", posts_index_url(page: @posts.next_page), remote: true)) if @posts.next_page %>');
# _post.html.erb
<div>
<h2><%= post.title %></h2>
<small><em><%= post.created_at %></em></small>
<p><%= truncate(strip_tags(post.body), length: 600) %></p>
</div>
a = 1.234
b = 5
(a - b).round # -4
(a - b).round(1) # -3.8
(a - b).round(2) # -3.77
(a - b).round(3) # -3.766
a = 1.234
b = 5
c = a - b
sprintf("%.f", c) # "-4"
sprintf("%.1f", c) # "-3.8"
sprintf("%.2f", c) # "-3.77"
sprintf("%.3f", c) # "-3.766"
sprintf("%.4f", c) # "-3.7660"
def resolve
if user.admin?
scope.all
else
scope.where(status: 2)
end
end
news = policy_scope(News).find(params[:id])
# ability.rb
...
elsif user && user.role?(:user)
...
can :read, :tags
# posts_controller.rb
def withtag
authorize! :read, :tags
if params[:tag]
@posts = Post.tagged_with(params[:tag]).order('created_at DESC')
@tagname = params[:tag]
@tag = Tag.find_by_name(params[:tag])
end
end
skip_authorize_resource :only => : withtag
load_and_authorize_resource :only => [:index, :show]
config.action_mailer.default_options = { from: 'твой email' }
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
user_name: 'твой email',
password: 'пароль созданный для gmail app',
authentication: 'login',
enable_starttls_auto: true
}
<%= f.select :dic_country_id, options_from_collection_for_select(@countries, "id", "country_name", значение_с_объекта) %>