Rails笔记

2015-05-06  本文已影响246人  ShindouHikaru
render plain: params.inspect
 rails g model Product --migration false
rails generate controller StaticPages home help
rails destroy  controller StaticPages home help

rails generate model User name:string email:string
rails destroy model User

rake db:migrate
rake db:rollback

rake db:migrate VERSION=0  #􏸯􏳷􏳭􏰐􏰤􏰗􏼞􏰁􏸯􏳷􏳭􏰐􏰤􏰗􏼞􏰁􏸯􏳷􏳭􏰐􏰤􏰗􏼞􏰁􏸯􏳷􏳭􏰐􏰤􏰗􏼞􏰁􏸯􏳷􏳭􏰐􏰤􏰗􏼞􏰁回到最开始的状态

􏳰􏰼􏸐􏳤􏳄􏳅+ Ruby<% ... %>􏷆􏺼􏺼􏰙􏰙􏶵􏱣􏰗􏵼􏵽􏰲 与 <%= ... %>区别􏰜􏲞􏺼􏰙􏶵􏱣􏰗􏵼􏵽􏰎􏲐􏵣 􏲞􏰏􏺼􏰙􏰗􏶗􏲘􏻖􏻖􏳅􏳅􏶈􏼭􏱣􏰥􏳲􏳭􏶤􏱔􏳷􏰗􏶍􏲣􏱸􏲫􏰧􏰛􏳊􏰎􏳇􏰮􏰎􏰾􏰿􏴹􏳖􏱣􏵟􏶋􏰗􏱹􏳢􏲌􏰮

<% ... %>#只执行其中代码
<%= ... %>#执行其中代码并插入模板中
users = User.all
    render json: users.as_json
skip_before_action :verify_authenticity_token
match '/:controller/:action',:via=>[:get,:post]
link_to 'about', :controller => "page", :action => "about"
Rails.cache.write(key,value) #存
Rails.cache.read(key,value) #取
render nothing:true
rails g controller wechat::third_party
=begin 路由定义
namespace :tech do 
    post 'register' => 'register#register'
    post 'verify' => 'register#verify'
  end
=end
rails g uploader xxxx
mount_uploader :url,ImageAvatarUploader#ImageAvatarUploader类名
sudo  apt-get install imagemagick #上传不入库缺少文件需要安装

因为新版的rails对mysql的支持使用的gem是mysql2,所以要在Gemfile中加上gem 'mysql2'一句;不过有了上面那条命令,rails会很聪明的自动在Gemfile中加上这句,so不用劳神鸟.

rails自然要下载安装mysql2包,不过这里会报错,提示找不到mysql的头文件,看来需要下载mysql dev包之类的东西,可以用如下命令安装:

sudo apt-get install libmysqlclient-dev
redirect_to controller: 'manage',action: 'tech_work_time'
flash.notice = "用户名密码错误!" #控制器

<% if flash.notice %>
  <div class="mui-toast-container notice">
    <div class="mui-toast-message"><%= flash.notice %></div>
  </div>
<% end %>
#视图application.html.erb
上一篇下一篇

猜你喜欢

热点阅读