Rails: conflict error overwrite /home/username/blog/.gitignore? - ruby-on-rails

I'm desperately trying to run a server and keep getting this mistake: conflict .gitignore
The output is:
rails new blog
exist
identical README.md
identical Rakefile
identical .ruby-version
identical config.ru
conflict .gitignore
Overwrite /home/jules/blog/.gitignore? (enter "h" for help) [Ynaqdhm]
What should I do? I'm using Ubuntu 20.04. I'm an absolute beginner.

When you run command $rails new it tries to create new rails application for you. But inside that folder that you are running this command file .gitignore already exists.
So, all that you need is to decide do you want to use your .gitignore file that already exists in current folder or to overwrite it with default one.
I think you made some mistake and just to make things simplier, try to run your command rails new blog in some separate empty folder.

It seems like you run rails new blog instead of rails s/rails server.
Since it already has all the files of a rails application called "blog", it's asking if it should overwrite the existing files with the new files it is creating because you ran rails new blog.

Related

Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first

I'm getting this error:
Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first
But I'm not in a rails directory, I'm on the desktop. There's no .bundle files anywhere to be found. Any ideas?
cd bin/
rm -rf rails
This fixed my problem. I was also getting the same error message
"Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first.
Type 'rails' for help."
I was struggling with this over the weekend, but after lots of prodding and poking got it to work.
The problem for me was that Aptana (I believe) created a second rails script in my local bin directory (~/bin) which was called instead of the system script. This local version was older than /usr/local/bin/rails. After moving aside ~/bin/rails, "rails new fred" worked as expected.
Try creating a new folder or rails app in root folder, under ~/
I was having the same problem this morning and that's because rails was already been there while i was creating my application.
To remove the error just go to bin folder of your application and remove the rails folder, and try to create new rails application in your planned folder using rails new app_name.

Creating new rails app dumps all the information in root directory

So I am having a strange issue. When I do rails new ~ whatever it creates all the files put slews them across my root directory in OSX. Even when I have specified to start in a different directory, it always places it all there. What am I doing wrong?
Thanks
Are you literally typing:
rails new ~ whatever
the rails command has the following usage:
rails new APP_PATH [options]
So it looks to me like you're trying to create a new rails app in your home dir. Try:
rails new whatever

Rails generate creates files in wrong folders

when I run a command like rails generate model Address Rails creates the model file and the migration file inside the config folder. A lot of other things are broken too. E.g. I can't launch the server because the configuration file config.ru cannot be found.
What's wrong here and how can I fix this?
I guess some paths are set incorrectly. But I wonder how that could happen because I haven't touched anything since yesterday evening.
Thanks for any help...
Try this
# in your development.rb file write this
config.paths['db/migrate'] += 'db/migrate/'
then run
rails generate model Address

Ruby on Rails config.secret_token error

I just started learning ruby on rails.
I followed a lot of install examples, but when i ran the example am getting this error
A secret is required to generate an integrity hash for cookie session data. Use config.secret_token = "some secret phrase of at least 30 characters"in config/initializers/secret_token.rb
I search for it but i dont see too much help.
plz help.
Platform: Mac OS X.
The easiest way to generate a new secret token is to run
rake secret
at the command line.
Your token should have been generated automatically by Rails, but you could still use something like:
irb(main):007:0> "#{ActiveSupport::SecureRandom.hex(64)}"
=> "921b00fcfabe0368d70627020f3b4c969cfd9bdc2474f4040c1ae976f687014694beb5d36dfc0c41bac8ebde96a14fceaee228d6e34d8183c5d7cc99d310d4f9"
meaning, you can generate some random string and put it into your config/initializers/secret_token.rb file:
# Be sure to restart your server when you modify this file.
Yourapp::Application.config.secret_token = '921b00fcfabe0368d70627020f3b4c969cfd9bdc2474f4040c1ae976f687014694beb5d36dfc0c41bac8ebde96a14fceaee228d6e34d8183c5d7cc99d310d4f9'
This is an issue with rails version probably. I had this issue when I uninstalled Rails 4 and installed Rails 3. After checking rails -v and seeing that it was indeed Rails 3, I executed rails new myapp. For some reason the configuration file config/initializers/secret_token.rb had the "config.secret_key_base" variable defined, which appears to be how Rails 4 does it. I was able to fix it by changing it to "config.secret_token", which I believe is what Rails 3 uses.
This simple command worked for me :
rvmsudo rake generate_secret_token
Make sure you have this in your environment.rb:
YourApp::Application.initialize!
Ran into this same issue and found out my config/initializers/secret_token.rb file was being ignored by git in my .gitignore file. Check out the config/initializers directory in your git source location and make sure the secret_token.rb file exists. If it doesn't edit your .gitignore file so that git will not ignore the secret_token.rb file and commit your changes (usually hidden - I used these simple commands to display hidden files on a mac http://osxdaily.com/2009/02/25/show-hidden-files-in-os-x/).

Possible to 'copy and paste' a whole Rails application?

I have a fully-functioning Rails application running on my local machine called 'first-app' in my Rails applications folder 'rails-apps'. I would like to create a second application in rails-apps (called 'second-app') which is identical to first-app, just with a different name.
Can I simply copy-and-paste first-app and rename the folder to 'second-app'? I have found only two files in the whole application which contain the term 'first-app' (application.rb and routes.rb, both in config), so presumably I would have to change their contents as well. If this 'copy-and-paste' approach is viable, are there any other files I would have to alter?
If I have to do the usual > rails new second-app, I must be able to copy and paste a lot of the files and folders from first-app. Which are the ones that I have to manually alter or construct with a rails command?
yes, it should works! Just replace in the copy-project the old terms('first-app') to 'second-app' and create a new database for the new app.
You can copy and past the first app folder and use the gem 'rename' to rename the copied app.
Follow these instructions: How to rename rails 4 app?
Just copy your app to a new folder :
$ cp your-old-app your-new-app
If you want to create a new database for the new app, in your config/database.yml rename the development database.
After that, all you have to do is
rake db:create db:migrate

Resources