SIDEBAR
»
S
I
D
E
B
A
R
«
ทำ Rails Server ให้เป็น Windows Services
Nov 22nd, 2011 by batt

ใช้ตัวนี้ได้เลย http://windowsrailsapp.sourceforge.net/ ใช้ง่าย ติดตั้งง่าย

วิธีติดตั้ง

  1. Download โปรแกรม
  2. ลงโปรแกรมตามปกติ
  3. เปิด service console (start/settings/Control Panel/Admin tools/Services) ดูว่ามี RailsAppLauncher service ถ้ามีเป็นอันเสร็จขั้นตอนการติดตั้ง

Configuration

  1. ไปที่ Folder “C:\Program Files\MA\Rails App Launcher”
  2. แก้ไขไฟล์ RailsAppLauncher.exe.config
  3. แก้ไขตามต้องการ กำหนด path และ port
  4. ตรวจสอบการทำงานโดยเปิด browser ไปที่ http://[servername]:[port]/
gem sources -a
Feb 20th, 2011 by batt

RubyGems will revert to legacy indexes degrading performance.
WARNING: ?RubyGems 1.2+ index not found for:
gem sources -a http://gems.github.com
gem sources -a http://gems.rubyforge.org
gem install … แว๊ก ERROR
Jan 12th, 2011 by batt

หลังจากไม่ได้ลง windows ใหม่ปีกว่า…
พอลง ก็ต้องลงโปรแกรมนั่นนี้ และที่สำคัญ Ruby on Rails เครื่องมีทำมาหากิน

ลง ruby ตามปกติผ่านฉลุย ไม่มีอะไรเกิดขึ้น

แต่…. gem install rails(หรืออื่นๆ)

ERROR:? Error installing pg:
The ‘pg’ native gem requires installed build tools.

Please update your PATH to include build tools or download the DevKit
from ‘http://rubyinstaller.org/downloads’ and follow the instructions
at ‘http://github.com/oneclick/rubyinstaller/wiki/Development-Kit’

เหอๆ ยังดีที่บอกว่าให้ทำอะไรบ้าง

ก็ไปโหลด DevKit ตามที่เขาบอกที่ http://rubyinstaller.org/downloads

แล้วทำตามขั้นตอนที่ http://github.com/oneclick/rubyinstaller/wiki/Development-Kit

สรุปให้แบบง่ายๆ unzip DevKit ไว้ที่ไหนก็ได้(แต่ folder ห้ามมีช่องว่าง)
แล้วก็ไปที่ folder นั้น แล้ว run ไฟล์ dk.rb
>> ruby dk.rb init
กับ
>> ruby dk.rb install
เสร็จ

แล้วลอง gem install rails (หรืออื่นๆ) ผ่านฉลุยแน่นอน

Using a proxy with open-uri
Jan 8th, 2011 by batt

ทำโปรเจค EBMWiz? ตอนตั้ง server ไว้ที่ office ก็ใช้งานได้ปกตินี่นา

แต่ทำไมพอย้ายไป server ไปไว้ที่ใน มข. มันใช้ไม่ได้

สงสัยว่าอาจจะต้องใช้ proxy ก่อน

require 'open-uri'
url = 'http://www.pubmed.com/'

proxy_addr = 'http://home.kku.ac.th/proxy.pac:'
proxy_port = '3128'

page = open(url, :proxy => (proxy_addr + proxy_port))

note ไว้ก่อน ลองแล้วได้ผลยังไงจะมา update ให้ฟัง

Remove div.fieldWithErrors from Rails forms
Dec 18th, 2010 by batt

In a decision I have never understood, Rails forms by default add <div> ... </div> around any field in your form that has validation errors on submission. Which sucks when you end up with markup like this:

<p>
  <div><label for="post_title">Title</label></div><br />
  <div><input id="post_title" name="post[title]" size="30" type="text" value="" /></div>
</p>

At work we?ve had a hack in place for a while not that dug into ActionView and turned off this nonsense. We normally don?t go highlighting form fields with errors anyway. As it turns out though, that HTML is actually rendered by a proc you can set. By default it looks like this:

ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| "<div class=\"fieldWithErrors\">#{html_tag}</div>" }

Just override this proc to return the tag only:

ActionView::Base.field_error_proc = proc {|html, instance| html }

In your environment.rb file, that would be:

config.action_view.field_error_proc = proc {|html, instance| html }

จาก :: http://d.strelau.net/post/163547069/remove-div-fieldwitherrors-from-rails-forms

ตัวอย่างที่ทำเอง เอาไว้ที่ controller

 ActionView::Base.field_error_proc = proc {|html, instance| %{<span>#{html}<span></span></span>} }
SIDEBAR
»
S
I
D
E
B
A
R
«
»  Substance:WordPress   »  Style:Ahren Ahimsa