class CustomersSessionsController < Devise::SessionsController
# ログイン後、リダイレクト先メッソドafter_sign_in_path_forをオーバーライドする。
def after_sign_in_path_for(resource)
#お気に入り登録(POST)の場合、after_login_to_post_pathに遷移します。
if session[:after_login_to_post]
after_login_to_post_path
else
super
end
end
end
class UsersSessionsController < Devise::SessionsController
・・・
def after_sign_in_path_for(resource)
if (session[:previous_url] == root_path)
super
else
session[:previous_url] || root_path
end
end
end
--encrypt
Encrypt the contents of the zip archive using a password which is entered on the terminal in response to
a prompt (this will not be echoed; if standard error is not a tty, zip will exit with an error). The
password prompt is repeated to save the user from typing errors.
% scala
Welcome to Scala version 2.11.5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_71).
Type in expressions to have them evaluated.
Type :help for more information.
scala> println("Hello World!")
Hello World!
scala> _
[kadosaway@imac ~]$ brew versions imagemagick
Warning: brew-versions is unsupported and will be removed soon.
You should use the homebrew-versions tap instead:
https://github.com/Homebrew/homebrew-versions
6.9.0-3 git checkout 8b2b988 /usr/local/Library/Formula/imagemagick.rb
6.8.9-8 git checkout 9efbcda /usr/local/Library/Formula/imagemagick.rb
...
$ cd ドキュメントルート
$ vim .htaccess
=============
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/$ [OR]
RewriteCond %{REQUEST_URI} ^/news/$ [OR]
・
・ CGI表示したいページを[OR]でつなげて記述していく
・
RewriteCond %{REQUEST_URI} ^/news/pickup/$
RewriteRule .* /routes.rb [L]
=============
2.routes.rbの作成
$ which ruby
---rubyのディレクトリ--- ←メモ
$ vim routes.rb
=============
#!---rubyのディレクトリ---
begin
require './model/application'
require './controller/application_controller'
LOAD_DIR = %w(model controller)
LOAD_DIR.each do |dir|
Dir.glob("./#{dir}/*.rb").each do |file|
require file
end
end
# コントローラ生成
controller_name = Application.get_controller_and_action_name[:controller]
action_name = Application.get_controller_and_action_name[:action] || 'index'
@controller = Kernel.const_get([controller_name, '_controller'].join.split('_').map(&:capitalize).join).new
# アクション呼び出し
eval "@controller.#{action_name}”
# view呼び出し
@controller.render
rescue Exception
# 例外発生時404 Not Found
puts 'Status: 404 Not Found\n'
puts 'Content-Type: text/html\n\n'
puts ''
puts '404 Not Found'
puts "ページは移動または削除されました。"
puts "トップページへ”
# エラーログに書き込み
$stderr.puts "#{$!} (#{$!.class})"
$stderr.puts $@.join("\n")
end
=============
3. model view controlle のディレクトリ作成
$ mkdir model
$ mkdir view
$ mkdir controller
$ vim model/.htaccess
=============
Deny from all
=============
$ cp model/.htaccess controller
$ cp model/.htaccess view
4. Application モデルの作成
$ vim model/application.rb
=============
class Application
ROOT_CONTROLLER = :top
DEFAULT_ACTION = :index
class << self
def get_controller_and_action_name
url_split = ENV['REQUEST_URI'].split('/').delete_if{|element| element.empty? || element.match(/\?/) != nil}
controller = url_split.first || ROOT_CONTROLLER
action = url_split[1] || DEFAULT_ACTION
{controller: controller, action: action}
end
end
end
=============
5. Application コントローラの作成
$ vim controller/application_controller.rb
=============
require 'erb'
require "cgi"
require "cgi/session"
class ApplicationController
attr_accessor :cgi, :session, :params, :controller, :action
def initialize
@cgi = CGI.new
@params = @cgi.params
@session = CGI::Session.new(@cgi)
@render_once = true
params_parse
@controller = Application.get_controller_and_action_name[:controller]
@action = Application.get_controller_and_action_name[:action]
end
def params_parse
if @params != nil
form_array = @params.map do |key, value|
if value.size == 1 && value.kind_of?(Array)
[key.to_sym, value.first]
else
[key.to_sym, value]
end end.flatten(1) end @params = Hash[*form_array] end def redirect_to(url, status=”REDIRECT”) print @cgi.header( { “status” => status, “Location” => url }) end def render(viewfile=nil) if @render_once viewfile ||= “view/#{@controller}/#{@action}.html.erb” @cgi.out(){ ERB.new(File.read(viewfile).force_encoding(“utf-8”)).result(binding) } @render_once = false end end end =============
class Barcode
require 'barby'
require 'barby/barcode/ean_13'
require 'barby/barcode/ean_8'
require 'barby/outputter/png_outputter'
def initialize(number, type = :ean_13)
@number = number.to_s
@type = type
end
# PNG形式でデータURIスキームを生成
def to_png_image
'data:image/png;base64, ' + Base64.encode64(Barby::PngOutputter.new(barcode(@type, @number)).to_png)
end
private
def barcode(type, data)
case type
when :ean_13 # 13桁の場合
Barby::EAN13.new(data)
when :ean_8 # 8桁の場合
Barby::EAN8.new(data)
end
end
end