text Ruby on Rails终端命令

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text Ruby on Rails终端命令相关的知识,希望对你有一定的参考价值。

rails new appname
cd appname
bin/rails server -> running the app and watching for changes

bin/rails generate scaffold ModelName title:string attribute2:type -> "scaffold" creates a model, view, and controller for a resource, all at once.

bin/rails db:migrate -> migrate the db with the created scaffold

bin/rails console -> perform ruby code and get evaluated by the console
  
  Read Operations:
  Post.all -> read all the info of the Post objects
  Post.last
  Post.find(3) get the post with id of 3
  
  Create Operations:
  post = Post.new -> create a new post 
  post.title = 'hello console' -> set a title on the post title
  post.save -> store it in the db
  
  Updating Operations:
  post = Post.find(3) get the post with id of 3 and assign it to variable
  post.title = "Update Title"
  post.save
  
  Delete Operations:
  post = Post.find(2)
  post.destroy
  
  type exist to leave the ruby console
  

bin/rails generate migration AddBodyToPost body:text -> Add body to Posts db
bin/rails db:migrate -> sync up with the db


bin/rails routes -> view all routes via console
Creating a Route:
in routes.rb do the following,
get '/pages', to: 'pages#index' -> GET requests for the '/pages' path should go to the PagesController's 'index' method.

Creating a Controller for the route (in Terminal):
bin/rails generate controller Pages

Create an index method inside pages controller
Create a view html.erb file to render the page back to client

Need to inject html.erb with modal (data) via the controller
Creating Model:
bin/rails generate model Page title:string body:text slug:string
followed by
bin/rails db:migrate

以上是关于text Ruby on Rails终端命令的主要内容,如果未能解决你的问题,请参考以下文章

打造适合Ruby on Rails的Sublime Text 3开发环境[原创]

在 ruby​​ on rails 中创建新表

Ruby on Rails:运行 rake 命令时出现错误消息

Ruby on Rails。捆绑器。黄瓜。耙中止!命令失败,状态为 (1)

Ruby on Rails 中的 Runner

如何使用 NuoDB 在 Ruby On Rails 中手动执行 SQL 命令