How to install and use a gem inside an rails engine - ruby-on-rails

I use refinery-cms to create a webshop in ruby-on-rails and refinery is largely based on engines. I have therefore made a "webshop" engine with all my models, and i want to install the gem "activeadmin" inside this engine, so when i run "rails g active_admin:install" it will create the model and config files inside my engine dir. I can only get it to install in the root app
Hope you can help me
/Johan

The solution to this was just to cd in to the engine folder, and run the generator command from there.

Related

Adding ruby on rails to an existing react native app

Background
I'm developing a React Native app for the first time. I've gotten to the point where I need to start working on the back end and I'm going to use Ruby on Rails to do that. I've installed Ruby and SQLite3, and I've successfully added Ruby to my project.
Problem
As of right now, when I try to install bcrypt and jwt to the Gemfile in the project, I ran gem install bcrypt/jwt and that seemed to work, but when I try to run bundle i get an error: "Could not locate Gemfile". I am certain the Gemfile is in the directory I'm running the commands in, as I can see it in VS Code and also going down the path in C:/, etc.
Question
Can I actually add Ruby on Rails to an existing project? What could be the cause of this issue?
Thanks a lot!
If you have created a new Rails-App via rails new myapp you can cd into this directory and call bundle install.
rails new myApp && cd myApp && bund
Please check that you are in the correct directory. If you are sure that you are in the right directory then check your current rails version with rails --version.
Make sure you are in the project directory before running bundle install. For example, after running rails new myproject, you will want to cd myproject before running bundle install.
gem install - like npm install -g, programm to fetch gems,
bundle is fetching list of gems from Gemfile in your app(current folder), like package.json (not sure about naming)
1. Can I actually add Ruby on Rails to an existing project?
Yes, sure. You have a lot of variation to do that
here link the good article how create rails-react app, then you can move your front end part to react folder in the new rails application.
you can create new rails as separated application, in folder what you want as API with option rails new your_app_name --api, then send requests from react app directly to rails app port or IP(it is harder to implement, but I think it is right solution).
2. What could be the cause of this issue?
it is possible because you do not have rails app do not exist
you do not have Gemfile in your folder.

using github for windows can't start rails server after pulling a repo

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.

RVM why don't gems install to locally to project folder?

So here's my problem:
I have a project and I am trying to install Gems locally to that project. For example if I install devise from the Gemfile and then run a bundle install it won't put any of the controllers in the controllers directory of the project. Instead I have to hunt through the RVM directories to get that particular gem's controllers, copy them to my project and then start writing my project from there.
Any suggestions?
I think the comment above answered your question - when you add a gem like Devise to your app, it doesn't generally drop code directly into your application. Sometimes it provides a generator which will install some parts of it, but mostly it alters config files so that the code in the gem gets pulled into your app when it starts.
You can ask bundler to install gems in the "vendor" subdirectory of your app, instead of in the main RVM/Ruby location, with the --path option. But you usually only want to do that for production deployment, not development.

Ruby on Rails generators with new gemified plugin?

I'm attempting to create a new Rails 3 plugin gem which wraps around devise/devise_ldap_authenticatable for reusable drop in internal LDAP support.
I create the new plugin gem with:
rails plugin new <gem_name>
I then add the devise/devise_ldap_authenticatable gems to the .gemspec file and run bundle
In the devise instructions it says to generate the required files using its generators:
rails generate devise:install
rails generate devise MODEL
However, in the directory where the plugin is generated I don't seem to be able to run rails generate. Most gem plugin tutorials instruct you to just create the files manually. Am I better off starting a new rails project, following the instructions in the temp project, then copying the files over to the plugin manually? Is there something that I'm missing? Can I run the generator script from the dummy instance? What is the standard practice in this use case?
In the end, I opted to forgo wrapping devise_ldap_authenticatable due to its relative simplicity.
The answer that I would go with in the future is to just to move files from a throwaway project.

"could not locate gemfile" when doing bundle install on existing rails project

I've been given an existing rails project that I am trying to play around with. however, when I try to run bundle install or rake db:migrate, I run into problems so essentially, i can't really do anything with the code I've been given.
The biggest problem as I see it right now is the fact that it can't locate my gemfile when I bundle install?
How can I find my gemfile.. is there supposed to be one in the root folder of the application?
Is there another step I need to take to initialize an existing project that someone has just copied and pasted to me? Thanks!
Yes, you should have a Gemfile in the root directory of your app.
If you are developing in a Rails 2 app, you might want to check out the Bundler.io page about Rails 2.3:
http://bundler.io/v1.7/rails23.html
If you are using Rails 3+ you can take a learn from Bundler's page on Rails 3 use:
http://bundler.io/v1.7/rails3.html
If you just need to get started with a Gemfile, go to a different directory and generate a dummy app:
$ rails new temporary-app
Copy over the Gemfile to your directory. It will only have the default gems listed, but you may be able to "discover" your needed gems as you go. If you happen to have a Gemfile.lock file then you can see the gems that you need at the top of the dependency tree.

Resources