Giter Club home page Giter Club logo

requestjs-rails's Introduction

Welcome to Rails

What's Rails?

Rails is a web-application framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.

Understanding the MVC pattern is key to understanding Rails. MVC divides your application into three layers: Model, View, and Controller, each with a specific responsibility.

Model layer

The Model layer represents the domain model (such as Account, Product, Person, Post, etc.) and encapsulates the business logic specific to your application. In Rails, database-backed model classes are derived from ActiveRecord::Base. Active Record allows you to present the data from database rows as objects and embellish these data objects with business logic methods. Although most Rails models are backed by a database, models can also be ordinary Ruby classes, or Ruby classes that implement a set of interfaces as provided by the Active Model module.

View layer

The View layer is composed of "templates" that are responsible for providing appropriate representations of your application's resources. Templates can come in a variety of formats, but most view templates are HTML with embedded Ruby code (ERB files). Views are typically rendered to generate a controller response or to generate the body of an email. In Rails, View generation is handled by Action View.

Controller layer

The Controller layer is responsible for handling incoming HTTP requests and providing a suitable response. Usually, this means returning HTML, but Rails controllers can also generate XML, JSON, PDFs, mobile-specific views, and more. Controllers load and manipulate models, and render view templates in order to generate the appropriate HTTP response. In Rails, incoming requests are routed by Action Dispatch to an appropriate controller, and controller classes are derived from ActionController::Base. Action Dispatch and Action Controller are bundled together in Action Pack.

Frameworks and libraries

Active Record, Active Model, Action Pack, and Action View can each be used independently outside Rails.

In addition to that, Rails also comes with:

  • Action Mailer, a library to generate and send emails
  • Action Mailbox, a library to receive emails within a Rails application
  • Active Job, a framework for declaring jobs and making them run on a variety of queuing backends
  • Action Cable, a framework to integrate WebSockets with a Rails application
  • Active Storage, a library to attach cloud and local files to Rails applications
  • Action Text, a library to handle rich text content
  • Active Support, a collection of utility classes and standard library extensions that are useful for Rails, and may also be used independently outside Rails

Getting Started

  1. Install Rails at the command prompt if you haven't yet:

    $ gem install rails
  2. At the command prompt, create a new Rails application:

    $ rails new myapp

    where "myapp" is the application name.

  3. Change directory to myapp and start the web server:

    $ cd myapp
    $ bin/rails server

    Run with --help or -h for options.

  4. Go to http://localhost:3000 and you'll see the Rails bootscreen with your Rails and Ruby versions.

  5. Follow the guidelines to start developing your application. You may find the following resources handy:

Contributing

We encourage you to contribute to Ruby on Rails! Please check out the Contributing to Ruby on Rails guide for guidelines about how to proceed. Join us!

Trying to report a possible security vulnerability in Rails? Please check out our security policy for guidelines about how to proceed.

Everyone interacting in Rails and its sub-projects' codebases, issue trackers, chat rooms, and mailing lists is expected to follow the Rails code of conduct.

License

Ruby on Rails is released under the MIT License.

requestjs-rails's People

Contributors

d6rkaiz avatar dependabot[bot] avatar dhh avatar dnwilson avatar kirillplatonov avatar marcelolx avatar nimmolo avatar npezza93 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

requestjs-rails's Issues

0.0.8 breaks Rails apps not using importmaps

% bundle exec rails c
/Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/railties-6.1.4.4/lib/rails/railtie/configuration.rb:97:in `method_missing': undefined method `importmap' for [...]
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/requestjs-rails-0.0.8/lib/requestjs/engine.rb:10:in `block in <class:Engine>'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/railties-6.1.4.4/lib/rails/initializable.rb:32:in `instance_exec'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/railties-6.1.4.4/lib/rails/initializable.rb:32:in `run'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/railties-6.1.4.4/lib/rails/initializable.rb:61:in `block in run_initializers'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/tsort.rb:228:in `block in tsort_each'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/tsort.rb:431:in `each_strongly_connected_component_from'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/tsort.rb:349:in `block in each_strongly_connected_component'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/tsort.rb:347:in `each'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/tsort.rb:347:in `call'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/tsort.rb:347:in `each_strongly_connected_component'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/tsort.rb:226:in `tsort_each'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/3.0.0/tsort.rb:205:in `tsort_each'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/railties-6.1.4.4/lib/rails/initializable.rb:60:in `run_initializers'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/railties-6.1.4.4/lib/rails/application.rb:391:in `initialize!'
        from /Users/me/Documents/app/config/environment.rb:5:in `<main>'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:35:in `require'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4.4/lib/active_support/dependencies.rb:332:in `block in require'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4.4/lib/active_support/dependencies.rb:299:in `load_dependency'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4.4/lib/active_support/dependencies.rb:332:in `require'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/railties-6.1.4.4/lib/rails/application.rb:367:in `require_environment!'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/railties-6.1.4.4/lib/rails/command/actions.rb:28:in `require_environment!'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/railties-6.1.4.4/lib/rails/command/actions.rb:15:in `require_application_and_environment!'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/railties-6.1.4.4/lib/rails/commands/console/console_command.rb:101:in `perform'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/railties-6.1.4.4/lib/rails/command/base.rb:69:in `perform'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/railties-6.1.4.4/lib/rails/command.rb:48:in `invoke'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/railties-6.1.4.4/lib/rails/commands.rb:18:in `<main>'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from /Users/me/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from bin/rails:4:in `<main>'

Let me know if you need any more information to help diagnose this.

The path is not recognized when using importmap

Hello!

Using Rails 7 and importmap, I added this gem and ran the installation steps.

However, it only adds the @rails/request.js import in application.js, without adding it to importmap.rb.

I tried to add it manually using any of these options:

pin '@rails/request.js', to: 'rails-requestjs'
pin '@rails/request.js', to: 'request.js'

And I get the following, as appropriate:

Importmap skipped missing path: rails-requestjs
Importmap skipped missing path: request.js

Then, I executed:

bin/importmap pin @rails/request.js

And I got the same result, even though the URL is associated in importmap.rb.

I removed the gem and everything was solved. Now I am using the CDN.

What could be happening?

Something extra I didn't mention is that I'm using propshaft, will it affect anything?

Thanks!

Refactor `Gemfile` and `.gemspec` to remove `rails` dependency?

Does this gem depend on all of Rails? As far as I can tell it only uses railties. I know it does depend on webpacker OR importmap also.

Our app skips importing significant parts of rails for efficiency because we don't use them, namely

activestorage
actioncable 
actionmailbox
actiontext 

and I believe this is not an uncommon practice. requestjs-rails would be our only dependency requiring all of rails.

An alternative is to just hand-code what this gem does in our js requests. But if the Gemfile/gemspec can be rewritten to only require railties or any other gems that requestjs-rails depends on, i'd be happy to submit a PR.

NoMethodError: undefined method `asset' for #<Array:0x00007f78c7582900>

This crash occurs when the engine loads, so on boot or running the install task.

Gemfile:

gem 'rails', '~> 6.1.4', '>= 6.1.4.1'
# ...
# the following are updated to the latest versions as of this writing:
gem 'importmap-rails'
gem 'hotwire-rails'
gem 'requestjs-rails'
./bin/rails requestjs:install --trace
** Invoke requestjs:install (first_time)
** Execute requestjs:install
** Invoke requestjs:install:asset_pipeline (first_time)
** Execute requestjs:install:asset_pipeline
rails aborted!
NoMethodError: undefined method `asset' for #<Array:0x00007f78c7582900>
/Users/william/programming/coffee-log-rails/config/environment.rb:5:in `<main>'
/Users/william/programming/coffee-log-rails/bin/rails:5:in `<top (required)>'
/Users/william/programming/coffee-log-rails/bin/spring:10:in `require'
/Users/william/programming/coffee-log-rails/bin/spring:10:in `block in <top (required)>'
/Users/william/programming/coffee-log-rails/bin/spring:7:in `tap'
/Users/william/programming/coffee-log-rails/bin/spring:7:in `<top (required)>'
Tasks: TOP => app:template => environment
(See full trace by running task with --trace)

The actual crash appears to be in lib/requestjs/engine.rb, line 12::

    initializer "requestjs.importmap" do
      if Rails.application.config.respond_to?(:importmap)
        Rails.application.config.importmap.paths.tap do |paths|
          paths.asset "@rails/request.js", path: "rails-requestjs" # line 12
        end
      end
    end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.