Setup Both SSH and SFTP Are Able to Login at Same Time in Ubuntu

這篇文章主要是參考自 http://blog.srmklive.com/2013/04/24/how-to-setup-sftp-server-ftp-over-ssh-in-ubuntu/ 但是,我沒辦法同時使用ssh和sftp

Read on →
Comments

[HOWTO] Transfer Capistrano 2 to Capistrano 3 Using Ruby on Rails

At First, Why I want to transfer from Capistrano2 to Capistrano3?

  1. Stability
  2. Performance

In Capistrano2,

First, I often stuck at precompile…

and sometimes I get [deploy:update_code] exception while rolling back: Net::SSH::Disconnect, connection closed by remote host”

Third, every deployments take about 10~15 minuates.

So…. that’s why I want to change to capistrano 3.

Read on →

HOWTO- 公司需要CEO, Blog也需要SEO!- Using Octopress

這篇其實是學習(翻譯)自 http://xit0.org/2013/05/seo-for-octopress-websites

第一步- 文章SEO: 更改你Octopress產生文章引擎的 Rakefile

desc "Begin a new post in #{source_dir}/#{posts_dir}"
task :new_post, :title do |t, args|
  if args.title
    title = args.title
  else
    title = get_stdin("Enter a title for your post: ")
  end
  raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
  mkdir_p "#{source_dir}/#{posts_dir}"
  filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}"
  if File.exist?(filename)
    abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
  end
  puts "Creating new post: #{filename}"
  open(filename, 'w') do |post|
    post.puts "---"
    post.puts "layout: post"
    post.puts "title: \"#{title.gsub(/&/,'&')}\""
    post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M')}"
    post.puts "comments: true"
    post.puts "categories: "
    post.puts "keywords: "      # 加在這邊
    post.puts "description: "   # 加在這邊
    post.puts "---"
  end
end
Read on →
SEO
Comments

[HOWTO]- Build a Step-By-Step Website Introduction Using crumble.js Instead of intro.js

Intro

Crumble.js is a interactive step-by-step tour based on grumble.js

you might want to check the demo site.

Please check this out => http://blog.tommoor.com/crumble

You can learn from this tutorial how to use crumble.js in your Ruby on Rails project.

In advance, I will show you how to deploy to AWS EC2 without pain~~~

Read on →

[HowTo]- Create Youtube Link in Ruby on Rails(using Slim)

In your view where you want to show youtube link

ex: app/views/products/show.html.slim

- if @product.youtube_url.present?
  = video_iframe @product.youtube_url

Create a helper

ex: I created in application_helper.rb

def video_iframeideo_iframe(src)
  content_tag("iframe","", {:width => 'XXX', :height =XXX> 'YYY', :src =>"#{src}"} )
end

Read on →

Comments

[HowTo] 讓使用者登入網站後,才允許Facebook留言 - ROR + Coffeescript + CSS + Devise

1.在Html page加上

    <div class="fb_comment_container">
    <div class="event_fb_blur">
        <p><a href="javascript:;" onclick="App.check_login_status();">請登入會員先</a></p>
    </div>
    <div class="fb-comments" data-colorscheme="light" data-href="http://XXX.OOO" data-numposts="50" data-width="600"></div>
    </div>

App.check_login_status() => 寫在application.coffee裏

2.加上CSS

目的:加上遮罩讓使用者無法點入留言

    .fb_comment_container {
      text-align: center;
      -webkit-border-radius: 10px;
      -moz-border-radius: 10px;
      border-radius: 10px;
    }

    .event_fb_blur {
      width: 800px;
      height: 95px;
      background: rgba(0, 0, 0, 0.8);
      margin: 0 auto;
      position: absolute;
      z-index: 100;
      left: 230px;
      padding: 0 14px;
      }

    .event_fb_blur p{
    position: relative;
    margin: 0 auto;
    color: white;
    font-size: 30px;
    cursor:pointer;
    line-height: 104px;
    text-decoration: underline
    }

3.在config/initializers/devise.rb 加上

目的:使得devise在登入成功或登出時,寫出session讓javascript可以知道是否有登入成功

      Warden::Manager.after_set_user do |user,auth,opts|
        auth.cookies[:signed_in] = 1
      end

      Warden::Manager.before_logout do |user,auth,opts|
        auth.cookies.delete :signed_in
      end

4.在app/controllers/application_controller.rb加上

目的:儲存之前瀏覽的位置,並且在登入成功後,導向回去

      after_filter :store_location

      def store_location 
        if (
          request.fullpath != "/account/sign_in" &&
          request.fullpath != "/account/sign_up" &&
          request.fullpath != "/account/password" &&
          request.fullpath != "/account/sign_out" &&
          !request.xhr?) # don't store ajax calls
        session[:previous_url] = request.fullpath 
        end

        if request.fullpath == "/admin_users/sign_in"
          session[:previous_url] = "/admin"
        end

      end

    def after_sign_in_path_for(resource)
       session[:previous_url] || root_path
    end

5.在app/assets/javascripts/application.coffee加上

目的:使用js來達成功能

    getCookie: (match) ->
        key = match + "="
        for c in document.cookie.split(';')
          c.substring(1, c.length) while c.charAt(0) is ''
          return c.substring(key.length, c.length) if c.indexOf(key) >= 0 
        return null

    check_login_status: () ->
        window.open('/account/sign_in','_self',width=600,height=300,
        toolbar=0,menubar=0,location=1,status=1,scrollbars=1,
        resizable=1,left=0,top=0)

    init: () ->
        is_signed = window.App.getCookie("signed_in")
        if is_signed is '=1' or  is_signed is '1' #剛登入成功時,is_signed的值是1,但是之後就會變成=1,顆顆~
            $(".event_fb_blur").css({"display":"none"})

    $(document).ready ->
        App.init()

完成!

Bug:

  1. 當頁面縮放時,遮罩不會隨著變動
  2. 尚未整合使用者留言後,可以直接記錄到user model
Comments