I am learning rails, I am working on windows 10, I have installed importmap and according to the documentation I can install js libraries however it doesnt work at all this way
bin/importmap pin jquery
I have tried:
rails importmap pin jquery
and I get:
Don't know how to build task 'importmap' (See the list of available tasks with `rails --tasks`)
How could I install js libraries in rails propertly by using importmap
Thnks for your help
Indeed, there is such a problem. There is no dependence on the operating system.
But it is not clear from your question whether you included importmap in an old project or created a new project.
The sequence of actions in which I bypass (I work on linux) this problem:
mkdir new_rails_project && cd new_rails_project
echo "source 'https://rubygems.org'" > Gemfile
echo "gem 'rails', '7.0.4'" >> Gemfile
bundle install
bundle exec rails new . --force # --css=bootstrap -d=postgresql if necessary, etc.
Result:
./bin/importmap pin jquery
Pinning "jquery" to https://ga.jspm.io/npm:jquery#3.6.1/dist/jquery.js
Related
In every setup describing a configuring an environment with rbenv and Bundler, the instructions are always to install bundle as a system gem, using gem install bundler. Often, they'll also recommend rbenv-bundler rbenv plugin, but the maintainers of rbenv discourage this.
What's not described is how to install Rails. Initializing a new Rails project creates a basic Gemfile for bundler. However, in order to initialize a Rails project, one needs to have Rails installed. It seems weird and even wrong to make a directory, write a basic Gemfile that includes Rails, run bundle install, and then initialize Rails to the current directory. In fact, I doubt that would even work well, if it worked at all.
So, does Rails need to be installed as a system gem with gem install rails? If so, how does one manage multiple versions of Rails, particularly with rbenv?
It totally makes sense to NOT install rails as system gem.
Without messing up rbenv or other ruby version manager you use, below are brief steps to create (initialize) a new Rails app from a directory with a Gemfile:
mkdir rails_app
cd rails_app
vi Gemfile # Edit it to include a rails version you need
bundle --path vendor # Wait for bundler to finish
bundle exec rails new ./
The last step would ask: Overwrite /path/to/rails_app/Gemfile? (enter "h" for help) [Ynaqdh]. Input y to get the default Rails Gemfile content.
Note: the above steps specify the local vendor directory (inside the rails app folder) to avoid installing gems to system global scope.
Answer is no, you don't install rails as system gem. Create a project folder, add .ruby-version file and add the ruby version you would like in this file i.e. 2.3.0. rbenv uses the version specified in this file and it won't be system's ruby.
Now you can do gem install bundler from this directory and create Gemfile and add your rails version. Now run bundle install and roll it on the tracks of RAILS.....
Force rails to vendor gems.
$ mkdir foo
$ cd foo
$ bundle config --local path vendor
$ rails new .
I'm quite newbie in ruby and ruby on rails and I'd like some clarification, if possible.
I'm currently having rails 4.2.6 installed on my development environment in which I have built a few projects. Now, for my new projects I'd like to use Rails 5, so I assume that if I type the gem install rails command will get me the latest rails verion and probably set it as default, so every time I want to create a new project by rails new my_new_project_name this project will have the latest version (currently v5).
My question is will my gem list contain both rails versions then or is it going to cause any conflicts and issues to my old porjects? so, if I want to work back on any of my projects which has the "old" version, won't affect of any changes, right? As far as I understand its the bundler who picks the version of each gem, right?
If thats the case, I assume same thing applies and for every other gem that I use for each project, right?
You will have all different versions. BUT you will need to add the version number for all gems to your gemfile
For example
and in the gemfile you state:
gem 'remotipart', '1.2.1'
Best thing to do when using different versions of a same gem is to use either rbenv or RVM to create different gemsets for each project. This way You can be sure that your project won't load by mistake another version .
I personally use RVM so i am going to let You know how to use it.
1) install RVM from here https://rvm.io
2 ) make sure You are loading RVM in your .bashrc or .bash_profile files from your home directory ( /home/your_username) . You can use this code:
export PATH="$PATH:$HOME/.rvm/bin"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
3) take a look at this page https://rvm.io/workflow/projects and choose how You want to set RVM for your project . i personally use .rvmrc because i am old school...but those are not recommended anymore because they need trusting and are slower. As a alternative You can use .ruby-version and .ruby-gemset files. But You can use .versions.conf also If You want. Let's say for now we choose to use .ruby-version and .ruby-gemset files.
4) cd into your project and run this command `rvm --ruby-version use 2.3.3#project1 --create' . This will generate those two files în your project . And everytime You will cd into this project RVM will pick-up the gemset automatically.
5) Do the step 4) for the second project also but replace 'project1' with 'project2' .
6) Now You can edit the Gemfiles of these two project and put the version of rails that You desire.
7) to install each project You need to cd into that directory and run command 'gem install bundler' ( only first time) and then You can safely do 'bundle install'
8) repeat 7) for second project.
9) You are all Done. Now You have different version of same gem in two different gemsets .
To also answer the other questions:
1) having în the same gemset multiple versions of same gem can lead to conflicts especially when doing 'rails new project ' from terminal since this doesn't require a specific version . I suggest to create different gemset before installing a new version of a existing gem on your machine. For example for this particular case we can do this
rvm use 2.3.3#rails5 --create
gem install bundler
gem install rails -v 5.O.0.1
And now we can safely do 'rails new project' . This way the new version of rails is inside a new gemset .
I Hope this will help You :)
I solved this kind of dependence issues by moving all my developments to docker. So now I have a unique environment for each project trough use of Dockerfile.
I also employ Makefile and compose.yml to automatize by ci. Hope that help.
I am working on a Rails 4 application and one of the requirements is to have all of the Gems that normally go into the Gemfile brought in locally to the machine for use. This includes Rails and after looking at many google search results I am not able to find anyone talking about using the Rails gem locally on a Rails project.
My train of thought here is to clone the rails project from Github locally and then using the bundler config path to target that directory for rails, but I am not sure how well will that solution work or even if it will work.
I will appreciate any input here or if anyone has experience with this situation I will appreciate any insight.
The bundle install does that ?
If you want to install any gem to your project go to the project root on cmd
$ gem install gemname
Doing that you locally installed the gem afterwards you want to make sure its loaded to your project so you can run
$ bundle install
And simply like that your gem is installed. Hope that helps
If you have your project on github, then you can clone it using command.
git clone github-repository-url
And then from that project directory, run command
bundle install --path vendor
It will install all your rubygems into vendor directory.
Im about to start work on another web application, I change directories to
/rails_projects
and enter
rails new blank
I then get this error
Error: Command not recognized
Usage: rails COMMAND [ARGS]
The common rails commands available for engines are:
generate Generate new code (short-cut alias: "g")
destroy Undo code generated with "generate" (short-cut alias: "d")
All commands can be run with -h for more information.
If you want to run any commands that need to be run in context
of the application, like `rails server` or `rails console`,
you should do it from application's directory (typically test/dummy).
I have reinstalled rails, and still same error, any ideas?
UPDATE:
It actually give me the same error when I type just
rails -h
rails
in cmd
For anyone with a similar error that may land here, this fixed it for me:
rake rails:update:bin
This will generate "new" versions of the binaries. Just say Yes when it inquires you to replace them.
I ran into a similar issue when trying to upgrade a Rails Engine from 3.2 to 4.1.
The culprit was the presence of script/rails which contained:
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/my_project/engine', __FILE__)
require 'rails/all'
require 'rails/engine/commands'
The problem line is there at the end: require 'rails/engine/commands. That was not allowing the full Rails CLI to load which omitted the new command. Removing that file solved my problem.
I'm pretty sure this wasn't the cause of your specific problem, but the symptoms were the same as mine and this was the first link in Google for the error message. Just passing along my findings to help anyone else that runs into this same situation.
It looks like the rails command believes it's inside of a rails engine, which is why a different set of commands are available to you. Notice the 'commands available for engines' text. New is not a command available for engines. I'm not sure why rails thinks the directory you're in is an engine, but likely your directory structure is mixed up somehow.
If anyone runs into this error and needs a last resort plan.
I ended up uninstalling rails, rvm, and installing a newer version of ruby and new gemset.
rvm implode
gem uninstall rails -v=4.0.2
gem uninstall railities
install rvm :
curl -L https://get.rvm.io | bash -s
rvm get stable
for mac:
brew install libtool libxslt libksba openssl
brew install libyaml
install ruby:
rvm install 2.0.0 --with-openssl-dir=$HOME/.rvm/usr
if you have error
rvm install 2.0.0 --with-openssl-dir=$HOME/.rvm/opt/openssl
install new ruby gems from website. Unpackage it then go to folder and run
ruby setup.rb
gem update --system 2.1.9
install rails (you can choose your version)
gem install rails --version 4.0.2
gem install railties
I did this, and now system is working normal again.
Create another directory and run $ruby -v, check which version is available. Now run rails new app_name. Try once after closing the terminal and restarting.
This happen to me when a require error occurred in a gem (dependency) while loading.
I added some collaborators to a rails project on github. They pull down the project using github for windows but then cannot start the rails server
rails server gives them the same output as typing rails
When we do ls we get:
From the Github directory I tried chmod -R 777 sindika but it didn't work. Why can't they pull down the project and start the server?
Seems like the version of your globally installed rails gem is different from the one the project is built on, so Rails don't recognize this folder as its project. Doing bundle && bundle exec rails s should do the trick. Another way to solve this would be to uninstall the current version of the Rails gem and install the one that corresponds to your project.