** tableize
rails console下,執行"Post".tableize 得到posts,table名稱
----------------------
sinatra 在tux下執行
** singularize 複數變單數
執行上方式同上
** pluralize 單數變複數
執行上方式同上
http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html
ruby php implode
ostr = '{ "data": ['
articles = Article.order("created_at DESC")
ostr = ostr + articles.map{|f| ' ["' + f.title.chomp + '", "' + f.file_url + '"] '}.join(', ')
ostr = ostr + "]}"
map 會把activerecord取出來,設給f
然後組字串,最後加上join
這樣就像implode功能,效果很好~~
articles = Article.order("created_at DESC")
ostr = ostr + articles.map{|f| ' ["' + f.title.chomp + '", "' + f.file_url + '"] '}.join(', ')
ostr = ostr + "]}"
map 會把activerecord取出來,設給f
然後組字串,最後加上join
這樣就像implode功能,效果很好~~
ActiveRecord Migration API
http://blackanger.blog.51cto.com/140924/122472/
Migration API
不設定主鍵
create_table :goods, :id => false do |t|
t.integer :good_id
t.string :good_desc
改變主鍵
create_table :goods, :id => good_id do |t|
t.string :good_desc
end
Migration API
不設定主鍵
create_table :goods, :id => false do |t|
t.integer :good_id
t.string :good_desc
改變主鍵
create_table :goods, :id => good_id do |t|
t.string :good_desc
end
....Ruby on Rails 目標?? --3--
http://ihower.tw/rails4/environments-and-bundler.html
Rails 啟動與應用程式設定 =>/config/application.rb
Rails 啟動與應用程式設定 =>/config/application.rb
....Ruby on Rails 目標?? --2--
basic 終於結束了!往下一個。上一個步驟,最多問題rails3有些指令是rails4不能用,其中route中的match,現在要指定get或post,反正目前搞不清楚,所以只能自己手動加route,先能跑就好,以後比較熟,再好好研究,不然一直卡住,先往下學。
===== button_to =====
如果用button_to,而產生route跟你要POST,後面補上
:method => :get
<%= button_to 'New event', new_event_path, :method => :get%>
這樣就ok~
解答來自下面連結
http://stackoverflow.com/questions/5221227/rails-button-to-fails-with-path-doesnt-exist-for-a-path-that-exists
RESTful 應用程式
http://ihower.tw/rails4/restful.html===== button_to =====
如果用button_to,而產生route跟你要POST,後面補上
:method => :get
<%= button_to 'New event', new_event_path, :method => :get%>
這樣就ok~
解答來自下面連結
http://stackoverflow.com/questions/5221227/rails-button-to-fails-with-path-doesnt-exist-for-a-path-that-exists
....Ruby on Rails 目標??
http://vimeo.com/35998909
參考:http://clickonchris.com/2014/02/beerdogging-mobile-phonegap-angularjs/
第一步:裝RVM,保持乾淨的環境,不要用原生環境
http://dylandychat.blogspot.com/2013/11/ubuntu-rvm-ruby-on-rails.html
http://blog.eddie.com.tw/2011/04/08/rvm-and-gemsets/
http://www.openfoundry.org/tw/tech-column/8513-rvm-ruby-environment-version-manager
http://ihower.tw/rails3/advanced-installation.html#
Ubuntu Desktop部份
看完,做完,心裡就有數了。
========================
http://my.oschina.net/zlLeaf/blog/149650
上网查了一下,说要在Gemfile上加上gem 'execjs' 和 gem 'therubyracer',但是就不告诉我到底Gemfile在哪里啊,那叫我这种菜鸟去哪里找这个文件喔,然后我把整个.rvm文件都找遍了,终于知道了原来Gemfile在项目文件夹里面,不再.rvm里。。。。。。
所以我在projectName(刚刚新建的那个项目)里面的Gamefile加上gem 'execjs' 和 gem 'therubyracer'(在END之前加啊,相信应该都看得懂的),然后运行bundle install之后就可以运行rails server启动服务器了,连关闭都正常了,太高兴了
=======================
另外 重開shell後,無效問題
http://www.openfoundry.org/tw/tech-column/8513-rvm-ruby-environment-version-manager
https://rvm.io/rvm/install
方法一:執行 source ~/.rvm/scripts/rvm
方法二:Put this in your ~/.profile or ~/.bashrc:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
按 http://ihower.tw/rails3/firststep.html 練習
http://ihower.tw/rails3/ruby.html
http://ihower.tw/rails3/basic.html
====basic===
match ':controller(/:action(/:id(.:format)))' 這無用,自己手動加route >>
get "events" => "events#index"
get "events/new" => "events#new"
post "events/create" => "events#create"
====basic===
@event = Event.new(params[:event]) 這裡在rails 4.0有變化
http://stackoverflow.com/questions/17335329/activemodelforbiddenattributeserror-when-creating-new-user
def create
@event = Event.new(user_params)
....
private
def user_params
params.require(:event).permit(:name, :description)
end
需改成這種寫法,底下說明為什麼要這樣
http://www.sitepoint.com/rails-4-quick-look-strong-parameters/
edit-update時,也是一樣要改成 permit方式
另外 update action,有錯誤訊息為
除了原有的post "events/update" => "events#update"
補上patch "events/update" => "events#update"
原理目前不知,查很久,找不到答案,加上path這段就行…
==================
http://ihower.tw/rails4/index.html
參考這個才是rails 4.1.....
=================
參考:http://clickonchris.com/2014/02/beerdogging-mobile-phonegap-angularjs/
第一步:裝RVM,保持乾淨的環境,不要用原生環境
http://dylandychat.blogspot.com/2013/11/ubuntu-rvm-ruby-on-rails.html
http://blog.eddie.com.tw/2011/04/08/rvm-and-gemsets/
http://www.openfoundry.org/tw/tech-column/8513-rvm-ruby-environment-version-manager
http://ihower.tw/rails3/advanced-installation.html#
Ubuntu Desktop部份
看完,做完,心裡就有數了。
========================
http://my.oschina.net/zlLeaf/blog/149650
上网查了一下,说要在Gemfile上加上gem 'execjs' 和 gem 'therubyracer',但是就不告诉我到底Gemfile在哪里啊,那叫我这种菜鸟去哪里找这个文件喔,然后我把整个.rvm文件都找遍了,终于知道了原来Gemfile在项目文件夹里面,不再.rvm里。。。。。。
所以我在projectName(刚刚新建的那个项目)里面的Gamefile加上gem 'execjs' 和 gem 'therubyracer'(在END之前加啊,相信应该都看得懂的),然后运行bundle install之后就可以运行rails server启动服务器了,连关闭都正常了,太高兴了
=======================
另外 重開shell後,無效問題
http://www.openfoundry.org/tw/tech-column/8513-rvm-ruby-environment-version-manager
https://rvm.io/rvm/install
方法一:執行 source ~/.rvm/scripts/rvm
方法二:Put this in your ~/.profile or ~/.bashrc:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
按 http://ihower.tw/rails3/firststep.html 練習
http://ihower.tw/rails3/ruby.html
http://ihower.tw/rails3/basic.html
====basic===
match ':controller(/:action(/:id(.:format)))' 這無用,自己手動加route >>
get "events" => "events#index"
get "events/new" => "events#new"
post "events/create" => "events#create"
====basic===
@event = Event.new(params[:event]) 這裡在rails 4.0有變化
http://stackoverflow.com/questions/17335329/activemodelforbiddenattributeserror-when-creating-new-user
def create
@event = Event.new(user_params)
....
private
def user_params
params.require(:event).permit(:name, :description)
end
需改成這種寫法,底下說明為什麼要這樣
http://www.sitepoint.com/rails-4-quick-look-strong-parameters/
edit-update時,也是一樣要改成 permit方式
另外 update action,有錯誤訊息為
No route matches [PATCH] "/events/update"
除了原有的post "events/update" => "events#update"
補上patch "events/update" => "events#update"
原理目前不知,查很久,找不到答案,加上path這段就行…
==================
http://ihower.tw/rails4/index.html
參考這個才是rails 4.1.....
=================
訂閱:
文章 (Atom)