Ruby on Rails - manually testing your models in ruby on rails- ruby on rails tutorial - rails guides - rails tutorial - ruby rails
Manually Testing your Models in Ruby on Rails
Testing your Active Record models through your command line interface is simple. Navigate to the app directory in your terminal and type in rails console to start the Rails console. From here, you can run active record methods on your database. For example, if you had a database schema with a Users table having a name:string column and email:string, you could run:
User.create name: "John", email: "john@example.com"
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
Then, to show that record, you could run:
User.find_by email: "john@example.com"
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
Or if this is your first or only record, you could simply get the first record by running:
User.first