顯示具有 Ruby 標籤的文章。 顯示所有文章
顯示具有 Ruby 標籤的文章。 顯示所有文章

2017年3月17日 星期五

little rails project

type>brand>size>products details

entroll date
entroll time
customer ID
customer gender
customer birthday
customer email
customer address
customer TAX
payment method
delivery


customer ID
modifydate
modifytime
order No
product bran No
product brand Name
product No
product name
product type
product quantity
remark

2017年3月2日 星期四

安裝RVM

參考資料:
http://rvm.io/

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3


\curl -sSL https://get.rvm.io | bash -s stable

2017年3月1日 星期三

Rails Command Line

參考資料:
http://guides.rubyonrails.org/command_line.html

Rails 筆記

 參考資料:Ruby on Rails實戰聖經

//外卡路由 config/routes.rb
match ':controller(/:action(/:id(.:format)))', :via => :all

//資料驗證ActiveRecord Validation app/models/event.rb
class Event < ActiveRecord::Base
    validates_presence_of :name #field name
end

//分頁模組 add the following in Gemfile
gem "kaminari"
controller:
@events = Event.page(params[:page]).per(5)
view:
<%= paginate @events %>

//show message
add it at app/views/layouts/application.html.erb before yield
<p style="color: green"><%= flash[:notice] %></p>
controller:
flash[:notice] = "completed"

//The diffirences between render & redirect_to
render:回傳action樣板,而不是重新導入action
redirect_to:重新導入action

//before_action
before_action :set_event, :only => [ :show, :edit, :update, :destroy]
def set_event
  @event = Event.find(params[:id])
end
action建議封裝,放在private or protected中

//Partial template
view檔案以"_"開頭,for example _form.html.erb
<%= render :partial => 'form', :locals => { :f => f } %>

//RESTful參數
event_path(@event)需要參數,根據HTTP動詞決定show、update、destroy
events_path毋需參數,根據HTTP動詞決定index、create

2017年2月23日 星期四

rails Q&A

Q:
rails s doesn't work.(an error while trying to load the gem 'uglifier')
Ans: 
sudo apt-get install nodejs

2016年11月9日 星期三

Rails Bootstrap安裝

**GemFile內新增
gem 'bootstrap-sass'

**安裝
bundle install

**import bootstrap
**app/assets/stylesheets/application.css
@import "bootstrap-sprockets"; // 放 bootstrap 前
@import "bootstrap";

**修改副檔名成scss
app/assets/stylesheets/application.css
change to 
app/assets/stylesheets/application.scss

**加入javascript
**app/assets/javascripts/application.js

//= require jquery
//= require bootstrap-sprockets