Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sahilbansal17/rails_interview_questions
Ruby on Rails Interview Questions
https://github.com/sahilbansal17/rails_interview_questions
Last synced: about 2 months ago
JSON representation
Ruby on Rails Interview Questions
- Host: GitHub
- URL: https://github.com/sahilbansal17/rails_interview_questions
- Owner: sahilbansal17
- Created: 2024-06-25T17:41:54.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-06-25T17:43:06.000Z (6 months ago)
- Last Synced: 2024-06-25T19:36:28.042Z (6 months ago)
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rails_Interview_Questions
Ruby on Rails Interview Questions## Difference between Gemfile and Gemfile.lock
Gemfile and Gemfile.lock
Gemfile:
• The Gemfile is a file used by Bundler in Ruby projects to manage gem dependencies.
• It lists the gems required for the application, specifying versions or version constraints.
• It allows specifying groups of gems (e.g., :development, :test) to be used in different environments.Gemfile.lock:
• The Gemfile.lock is generated by Bundler to record the exact versions of all gems and their dependencies.
• It ensures that the same versions of gems are used when the application is deployed or shared.
• This file is crucial for consistent environments across different setups (development, testing, production).## Difference Between has_many :through and has_and_belongs_to_many
has_many :through:
• Used to set up a many-to-many connection with another model through a third model (a join model).
• Allows for more flexibility as the join model can have additional attributes and validations.
• Example:```ruby
class Author < ApplicationRecord
has_many :authorships
has_many :books, through: :authorships
endclass Authorship < ApplicationRecord
belongs_to :author
belongs_to :book
endclass Book < ApplicationRecord
has_many :authorships
has_many :authors, through: :authorships
end
```has_and_belongs_to_many (HABTM):
• Used to set up a many-to-many connection directly without a join model.
• Simpler to set up but lacks the flexibility of adding additional attributes or validations to the join table.
• Example:```ruby
class Author < ApplicationRecord
has_and_belongs_to_many :books
endclass Book < ApplicationRecord
has_and_belongs_to_many :authors
end
```