In episode 389 of Railscasts, he creates a method called scope_schema which is both a method being used throughout the episode but also being passed as a block with do
Can any method be done as such? What does the (*paths)
stand for? And how can I just create a method that can be a block? I looked at the link_to
source code and noticed at the end &block
which could make send given you can do
<%= link_to ....%>
or
<%= link_to ... do %>
<%end%>
Or am I incorrect?
Episode code:
after_create :create_schema
def create_schema
connection.execute("create schema tenant#{id}")
scope_schema do
load Rails.root.join("db/schema.rb")
connection.execute("drop table #{self.class.table_name}")
end
end
def scope_schema(*paths)
original_search_path = connection.schema_search_path
connection.schema_search_path = ["tenant#{id}", *paths].join(",")
yield
ensure
connection.schema_search_path = original_search_path
end