Posts

Showing posts with the label ror

NoMethodError: undefined method `has_many?'

NoMethodError: undefined method `has_many?' In your gem file-  group :test do     gem 'capybara', '~> 2.1.0'     gem 'shoulda-matchers', '~> 3.0' end Run - bundle install in your spec_helper-  Shoulda::Matchers.configure do |config|   config.integrate do |with|     with.test_framework :rspec     with.library :rails   end end In to do TodoItem model require 'spec_helper' describe TodoItem do   it { should belong_to(:todo_list) } end In to do TodoList Model require 'spec_helper' describe TodoList do   it { should have_many(:todo_items) } end

DmL command || Sql Tutorial -7

DML Command Insert Command Its used to insert the record into table example- Command for inserting single record insert into <table name> values(value1, value2...) Command for inserting multiple command at a time insert into <table name> values(&col1, &col2...., &coln); whenever you enter query like this it will ask you to like this - enter a value for column1- value1.. and then hit enter  - enter a value for column2- value2.. and then hit enter - enter a value for column3- value3.. and then hit enter Now it will show 1 row created  if you want to create more record use / and hit enter SQL> /   hit enter // it will Execute most recent query again //this will so again and so on... - enter a value for column1- value1..  and then hit enter  - enter a value for column2- value2..  and then hit enter - enter a value for column3- value3..  and then hit enter // if you will miss any value here that will be inserted as NULL value Update command Used to upda

Difference Between select and collect

Difference Between select and collect Select & collect select return array of hash of all field into a table Example user.select(:id) // it will return all fields with id user.all.collect(&:id) // it will array of id's

Difference Between pluck and collect

Difference Between pluck and collect Pluck Pluck takes less time then collect because when we use collect we have to execute two queries for collecting record Example-  When have a user table and we have to collect all id's User.all.collect(&:id) // when we use collect we are running two query internally                                        first user.all and then we collect id's User.pluck(:id) // Here we are running only one query that's why it take less time Pluck also take more than one parameter at a time but collect can not Example- user.pluck(:id, :name) // it will return array of id and name user.collect(&:id , &:name) // it will give an error

DDL command || Sql Tutorial -6

DDL Command CREATE Command It is used to create any data base object like tables, views, indexes, sequences, synonyms , users, functions, procedures, triggers, packages and so on. HOW TO CREATE A TABLE?            syn: CREATE TABLE <table_name>             (              <colname1> DATATYPE (size),               <colname2> DATATYPE (size),                : : : :,                : : : :,             ); INSERT Command This command is used for inserting new records into the tables          Syntax:           INSERT INTO <table_name>[(col1, col2,...., col n)]           VALUES(val1, val2,.....,val n);                  NOTE:  i) If number of columns in the table and number of values inserting in to the table      are equal, then no need to specify column names while inserting records.            ii) Char, Varchar2 and date type values should be enclosed in Single Quotes.            iii) If Number of inserting values are less than the

Create react app by live-server || live Server || React App

Image
First install node and check node -v and npm -v Create a directory mkdir <your_directory_name> Run command npm init (press enter and use all defaults) by this command package.json file will be created in root directory for creating Dependency we run this command npm install --save-dev babel-cli babel-preset-react npm install --save-dev babel-cli babel-preset-env sudo npm install -g  babel-cli babel-preset-env babel-preset-react ( Installed "babel-cli@6.26.0" with binaries:  - babel-doctor  - babel - babel-node  - babel-external-helpers ) this packages are created. Install live server npm  install  -g  live - server Now again make a directory inside root directory mkdir public (you can take name as you want) mkdir src (you can take name what ever you want you want) inside public folder create two new file index.html index.js inside src folder create one new file  main.js ( this is file where react app execution is start. you can take

Open rails server console on Terminal/Command Prompt

Login to Server via SSH or PEM file ls cd <domain name> cd/current RAILS_ENV=production bundle exec rails c now you will be in server console