Previous Ruby on Rails application in Cloud9 running on server - ruby-on-rails

I'm new to Ruby on Rails and working through some tutorials, using Cloud9 as an IDE. I recently switched to making a second app only to find that the first one runs on the server available for preview. I have tried starting the new app with $ rails server -b $IP -p $PORT. I have tried stopping the server on the first app with Ctrl + C in the command box. None of this is doing anything. The first application is the only one that displays.
Can someone please explain what is going on? How do I associate the base URL in Preview with the one set in the routing of my new application and why isn't this being done automatically?

Okay, I think the following will work on C9. But personally, I still think separate workspaces would work best.
Create a new project in C9, this will create a new workspace for you. While the folder tree will display the name of your project, the terminal will display ~/workspace. The two are synonymous (for now). This will be your first rails project.
To create a second project within the same C9 space, do the following:
In terminal, cd .. to go up one level. This should take you to the root ~ directory.
Type rails new <name-of-second-project> to create a new project.
At the top of the folder tree, click on the gear wheel. Unselect Show Root File System and Select Show Home in Favorites.
If you look at your folder tree now, you should see both of your rails projects. The first is listed as workspace and the second is whatever you named your second project.
If you want to rename workspace to match the actual name of your project, mv workspace <name-of-first-project>.
That's pretty much it. You can now navigate into each folder and treat it as a separate rails project. When using rails s -b $IP -p $PORT in the terminal, just make sure you're in the correct directory, depending on which project you want to run the server for and it'll work.

Related

RubyMine: Rails server launcher wasn't found in the project

After importing an existing project into RubyMine, I encountered "Rails server launcher wasn't found in the project" when I Run/Edit Configuration.
I've checked this Cannot start the debugger in Rubymine. Rails server launcher wasn't found in project, but deleting the .idea directory and re-open is not helpful.
I can rails server in the Terminal successfully and the rails server runs. So I guess it's likely a RubyMine related thing.
Thanks,
Allen
The easiest way to fix it:
Close project
Remove .idea folder from project folder
Open project
Bingo!
NOTE: this workaround seems to no longer work with 2017.2. See RUBY-20144
I upgraded from RubyMine to IntelliJ Ultimate IDE 2017.1.5 and I encountered the same error "Run Configuration Error: Rails server launcher wasn't found in project". I was using Ruby v2.4.0 with Rails 5.0.2.
It took me an entire day to solve the issue, so I've written a detailed explanation with screenshots to guide others.
It occurred when I tried to Run or Debug my Rails server from within IntelliJ.
Other solutions also didn't fix the error. I tried deleting my .idea/ folder, trying different Ruby or Rails versions (i.e. Ruby v2.3.0 or latest Rails 5.1.2), and even starting a brand new project from scratch. But I could run the Rails server fine using Terminal (outside the IDE) with rails s.
SOLUTION approach:
First I opened Run > Edit Configurations but "Choose SDK from module" didn't have any Project Modules available to select from the drop-down, so I had to create one as follows:
I went to File > Project Structure
Then I clicked Modules, and clicked the icon "+", and selected "Import Module".
Then I navigated to my Rails project's root directory "'/Users/my_username/code/apps/_murmur/skag_server_rails" and clicked Open, which displayed the following.
I then selected "Create module from existing sources" and clicked "Next", and it showed the following, with a blue checkbox shown next to my Rails project root directory that it found, so I clicked "Next" again:
It then showed the following window, and I clicked "Finish".
I'd now finished importing the Rails project I was working on as a Module, and it showed the following, so I clicked "Ok", as I was now ready to try and run my Rails server again:
So I went back to Run > Edit Configurations window and click on "Rails > skag" where I could now use "Choose SDK from module" since there was now my "skag_server_rails" Module available in the drop-down that I just created, and no errors were apparent, as shown below:
I was then able to click Ok to save the Run/Edit Config
I was then able to run the server Run > Run, which displayed:
I was then able to successfully open the Rails app in the browser open http://localhost:3000
But then when I tried to Run > Debug so I could debug using breakpoints, it gave me the following errors:
I solved this by running the following in the Terminal (outside the IDE):
gem install debase --pre
gem install ruby-debug-ide
Then finally I could run Run > Debug and it allowed me to trigger breakpoints as shown below:
Important Note:
The initial approach that I took that DID NOT end up fixing the error involved choosing to use "Use other SDK" within the Run > Edit Configurations window to load my Ruby Gemset into the debug configuration (instead of using a Module).
UPDATE: I encountered the same error again more recently on 2nd September 2017 and followed these steps to overcome it:
Go to Menu > File > Project Structure > Project Settings > Modules > Click "+" and select "New Module"
Select "Ruby on Rails" from the left hand side list
Choose for "Module SDK" label your "RVM: ruby-2.4.1 []"
Click for "Rails Version" label the "Install Rails Gem..." drop-down
Select a Rails version for it to download and wait (i.e. 5.0.0)
Do not select a Rails version that causes the tooltip "This version is not fully supported" to appear below (i.e. selecting a Rails version >5.1.2 causes this to occur)
Click for "Rails Version" label the version that finished downloading from the drop-down (i.e. 5.0.0)
Enter "Working Directory" label value of "../"
Enter a "Module Name" (i.e. videotube-5.0.0)
Click "Apply" and "Save"
Go to Menu > Run > Edit Configurations
Change any directories that do not point to root folder of app
Go to Menu > Run > Debug
My variant to solve same problem.
Create new run configuration, but use "Ruby" template instead of "Redmine":
Ruby script field set to path to your redmine rails bin path and Script arguments set to "server -b 127.0.0.1 -p 3000 -e development" for ex.
This worked for me
Remove the .idea file
Invalidate the cache and restart the ide
Ok, this RubyMine has some serious issues. My day started out peaceful and then ended as a nightmare, courtesy of RubyMine. All I did was git checkout to a certain version of my repo. Well, when I did that, suddenly the folders in RubyMine disappeared. Yes, that is the first bug. I git checkout 8d4fbd1b5dfce0a3daa16896a603903a And then I open RubyMine and folders are gone! I closed and reopened. Still no folders. I restarted computer and still no folders.
I had to go to Project > File Structure and delete the Module. And then create a new Module. Now the project folders appear. But then I get this obscure error Rails server launcher wasn't found in the project. I have no idea what it means. I go online and they say delete .idea directory in your project. So I do that. And now again I have to delete and recreate the module.
This time it says "overwrite directory" since I have an existing project. I select "Yes" and then I open project and my secrets.yml is gone! Now I had to use secrets.yml I had backed up. And then finally it works.
Seriously, all this just because I wanted to checkout out a specific git commit? Come on.
UPDATE
After further investigation, I understand what is going on. There are three critical Intellij Idea files with regards to the Ruby plugin:
/.idea/
MyProject.iml
/MyProjectGemset/
These three files should not be checked into git and should be consistent across the different branches of your project. You might have another *.iml in the project. Delete that and make sure you are using the same .iml throughout the branches.
These two files pertain to your SDK:
MyProject.iml
/MyProjectGemset/
This file pertains to general configuration:
/.idea/
I've came across this same problem, and a way I found to solve it was to properly defining the root folder of the project when opening it in the first time with RubyMine.
As far as I can understand, ideally you should open the project by pointing the RubyMine to the project's root folder:
my-workplace/
|-- rails-project-name/ <-- point RubyMine here when openning
| |-- app/
| |-- bin/
| |-- config/
| |-- db/
| |-- lib/
| |-- log/
| |-- public/
| |-- test/
| ...
if you follow the solution from Artyom Blagoda on the Windows with ruby installed on the WSL (Ubuntu) you'll get into situation when wsl path (\wsl$\Ubuntu) of ruby script (rails) could not be found by remote (Ubuntu) ruby interpreter. to make it work you need to add path mapping on:
Settings -> Ruby SDK and Gems -> Your remote ruby or RVM -> then click the folder icon above, you'll find a new window where you put:
Local Path: //wsl$/Ubuntu/PATH_TO_YOUR_RAILS_BIN
Remote Path: PATH_TO_YOUR_RAILS_BIN
hope it helps ;)

Can not create rails apps anymore under Ubuntu

I have a problem with all my three! Ubuntu systems. I can't create any Rails projects anymore with the following command
rails new abcde
I get the following error message.
Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first
I know the error message is really clear, I googled and checked all the entries here on StackOverflow. No one had another explanation other than there is a project in a parent folder, which is not the case in my systems!
I checked all folders back to root for any hidden files resembling a rails project. Nothing! I even created a new folder under root /projects and tried to create a project in there, same error. I don't know what to do anymore, I have the same problem on all three of my Ubuntu computers. Has anyone ever had this problem and could fix it? What could be another cause of this. Because there is no project in any of parent folders.
The only possible solution for me is, that there is maybe a PATH variable for Rails that I don't know about and there is maybe a project in there?
SUGGESTIONS:
0) I'm assuming you're typing these commands from a console window, and not executing a shell script, shortcut, or "something else". Correct?
1) Please update your post with the following: ruby -v; rails -v (Ruby and Rails version info)
2) Please try another test project, and copy/paste any error or warning messages you see:
cd /tmp
rails new abc -f
<= another test "rails new", with "--force" option
3) Assuming you've installed RVM, and assuming your "rails new" is calling "run bundle install", then also make sure your user is a member of the "rvm" group:
sudo usermod -G rvm -a MYUSER
4) If you haven't already, please also look at these links:
can't initialize a new rails application within the directory of another
Problems with RVM and Rails when creating new app

Creating a Rails app in workspace directory of Cloud9 IDE

When I run rails new . hoping to create a new Rails app in my workspace directory, rails says:
Invalid application name 567101. Please give a name that does not start with numbers.
How do I get around this? I could just create it within the top level directory, but that seems inelegant. When you create a workspace and select "Rails" for the type it sets up the app nicely in the right place, but I want to set up a Rails 4 app, so that's not an option.
I was just trying to figure this out myself. What I ended up doing is creating a symbolic link to the numbered directory named rails_app. I was then able to do a rails new and have it create the application.
First
cd ~/
Then
ln -s ./567101 ./rails_app
Then
rails new ./rails_app

Ruby on Rails -- new install on windows 7 but cant run ruby commands, problem with path?

I just installed ruby on rails on my new computer ( I was using instantrails before) and I'm trying to get everything setup.
Im running Windows 7. So I followed the instructions from this tutorial.
http://blogupstairs.com/ruby-on-rails/installing-ruby-on-rails-on-windows-7/
The problem i'm guessing is step 3
"Add the newly installed bin directory to your path in your windows system : Open windows explorer-> right click the icon computer-> choose Properties -> in the contol panel Home, Click Advanced system settings and then click Envitonment Variables button->in the system variables click new and add new system variables like this : Variable name : RUBY_HOME , Variable Value : C:\Ruby, after that add it in to the path and add the bin after a semicolon to the “Path” variable like this : C:\Program Files\Common Files\Adobe\AGL;%JAVA_HOME%\bin;%ANDROID_HOME%\tools;%RUBY_HOME%\bin"
I set created the system variables but when I try to run script/generate in the main directory of my app I get the error
"Ruby: no such file or directory --script/generate"
I checked the apps directory and the script folder is in there. How can I run the "ruby script/generate" commands from the control panel?
I was guessing it was something with the path but I dont know any ways to check to find out whats going wrong.
Are you using Rails 3.0+? In this version of rails and up, the script/* folder has been deprecated in favor of rails generate, rails server, etc. See here.
In 99.99999% of all cases, if a computer tells you that it cannot find a file at a specific location, it is because that file is not at that specific location.
So, is there actually a file named generate in a directory named script in the current directory?
I have recently installed RoR on my "clean" Win7 as well.
What IDE are you using?
I suggest trying JRuby with NetBeans/RubyMine:
JRuby installer does all the work (even adds the proper variables to your path in system environment settings...,
IDEs take care of gems, setting up servers etc.
As for the commands, as Nuclearsandwitch mentioned, there is no script/generate or script/server in Rails 3. Just make sure you in the directory with your Rails app and then try running rails server. It should work :-)

A question in rails db:migrate

Now , I execute the command line "rake db:migrate" on the window OS, but I got the problem in the console. it print couldn't find HOME environment -- expanding~/.ruby-uuid'`
who can help me to solve this ? Thank you and best regards!
I think i should add the home path in the window environment . but i don't know ,which folder should i specify add in the $home path? anyone can tell me the specific folder of the home path?
right click on My Computer > Advanced tab > Environment variables button, add a new variable called HOME with the full path to your home folder.
welcome to your first of many problems with gems that are not tested with windows. in unix systems, HOME is always defined, and files that start with . are invisible. apps create . files in your home directory to store user specific settings all the time.
unfortunately, a very small percentage of ruby devs use windows for dev work, which is why most people either recommend getting a mac, or installing linux

Resources