-
start by making the controller:
$ bin/rails generate controller Usage: rails generate controller NAME [action action] [options]
... ...
Description: ...
To create a controller within a module, specify the controller name as a path like 'parent_module/controller_name'. ...
Example:
rails generate controller CreditCards open debit credit close
Credit card controller with URLs like /credit_cards/debit -> /credit_cards/credit -> /credit_cards/close (If you don't specify actions it creates default CRUD actions (Ex. Create, update, delete, index -> you can google these) It will create: Controller: app/controllers/credit_cards_controller.rb Test: test/controllers/credit_cards_controller_test.rb You will want to create (Possibly) Views: app/views/credit_cards/debit.html.erb [...] Helper: app/helpers/credit_cards_helper.rb
-
Generate your model: your DB is generated off of the model. Your db keys are generated based off of active record associations (has_many etc: http://guides.rubyonrails.org/association_basics.html)
$ bin/rails generate model Usage: rails generate model NAME [field[:type][:index] field[:type][:index]] [options]
ex. bin/rails generate model CreditCard type:String name:string number:integer etc:etc
...
Active Record options: [--migration] # Indicates when to generate migration # Default: true
...
Description: Create rails files for model generator.
-
After creating your model, you need to run the db changes:
$ bin/rake db:migrate
-
Make sure your routes are set up properly
-
Implement whatever actions you created for your controller ex. def credit // debit code here, anything you want to use on html page use @variableName end def debit // credit code here, anything you want to use on html page use @variableName end def close // close account code here, anything you want to use on html page use @variableName end
ruby-notes's Introduction
ruby-notes's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.