Error launching Rails server: undefined method 'configure'

前端 未结 5 1656
情歌与酒
情歌与酒 2020-11-28 06:04

I\'m new to rails and working through Hartl\'s tutorial. Everything was fine until I tried to do the tutorial a second time and created another project trying to use the lat

相关标签:
5条回答
  • 2020-11-28 06:23

    I resolved it by doing following step.

    Step 1: go to Project_Root_Directory/config/environment/development.rb

    Change this line

    Rails.application.configure do
    

    To

    Your_Rails_Application_Folder_name::Application.configure do
    

    For example my rails project folder name is 'Spree_demo' so Your_Rails_Application_Folder_name in the following line:

    Your_Rails_Application_Folder_name::Application.configure do
    

    will be replaced as

    SpreeDemo::Application.configure do
    

    Note: See underscore in your application folder name it gets removed.

    Hope it works for you guys.

    0 讨论(0)
  • I had this issue when I messed around with my Gemfile. For example I have created the app using rails 4.0.2 or something like that then due to some errors I changed it to 4.1.1 that change cause this exact same problem in both development and production

    0 讨论(0)
  • 2020-11-28 06:24

    That happened to me too. The problem was that I used one version of Rails to create the project. Then I changed the Gemfile to use another version of Rails and the system was using it to scaffold or run the server. Newbie problem! Using the same version consistently should solve the problem. :-)

    0 讨论(0)
  • 2020-11-28 06:37

    I posted a (probably way too long) answer in a similar question: rails - NoMethodError: undefined method `configure' for FirstApp. This thread actually started me on the way to my eventual solution, so I thought I'd post here as well just in case it's helpful to anyone else.

    From what I can tell, the problem occurs when the app/config/initializers/development.rb (and production.rb) files are generated for a new project using some newer versions of Rails (I'm not sure in which version it started, I only tested Rails 4.1.4). Mr. Hartl uses Rails 4.0.8 for his tutorial, and that's the highest version I tested in which the new syntax doesn't occur.

    In Rails 4.1.4, and maybe some other versions after 4.0.8, the first line in those files is generated as Rails.application.configure.do rather than, using a project called sample_app as an example, SampleApp::Application.configure.do as in 4.0.8.

    I'm new to Rails so I don't know why this syntax changed in newer versions. I'm assuming it's intentional and somehow better than the old way. Most likely, Mr. Hartl will take it in to account in future editions of his tutorial that are updated for versions of Rails which include this change.

    Until then, see my other answer in the question I mentioned above for a more thorough explanation of how I got around it on Windows 7, but the tl;dr of it is:

    Make sure you're using the version of Rails specified for the tutorial (4.0.8) in your local repository/root development directory before you create your new project. Updating your Gemfile after creating the project is still important, but it won't solve this problem if the files themselves were generated with a newer version of Rails. You'll have to go in and edit that line manually in that case, as other users have suggested.

    0 讨论(0)
  • 2020-11-28 06:39

    First set Ruby version before Rails new

    I had the same problem and I tried the answer given and it had no impact. I even tried changing the name to get rid of the underscore, and it had no impact.

    The problem is that you did this:

    $ rails new app_name

    But your ruby version was probably 2.1.1 or something else. You want to do:

    $ rvm 2.0.0

    BEFORE you run the new app, and then when you set 2.0.0 in your Gemfile (as Hartl recommends) it falls into place.

    I don't know WHY this works, and I hope someone will shed light on it, but I can tell you that this worked better than the answer that is currently in the lead.

    0 讨论(0)
提交回复
热议问题