启动rails服务器但localhost页面不会加载

时间:2016-11-03 23:39:32

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 ruby-on-rails-3.2

我启动了rails服务器

private TransferHandler handler = new TransferHandler() {
    public boolean canImport(TransferHandler.TransferSupport support) {
        if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            return false;
        }

        Transferable t = support.getTransferable();

        try
        {
            java.util.List<File> l = (java.util.List<File>)t.getTransferData(DataFlavor.javaFileListFlavor);
            File file = l.get(0);
            String fileName = file.getName();

            if (!file.getName().endsWith(".java"))
                return false;
        }
        catch (Exception e)
        {
            // ignore
        }

        if (copyItem.isSelected()) {
            boolean copySupported = (COPY & support.getSourceDropActions()) == COPY;

            if (!copySupported) {
                return false;
            }

            support.setDropAction(COPY);
        }

        return true;
    }

但是当我转到http://localhost:3001我收到错误时:找不到此本地主页

这是我继续http://locahhost:3001后在终端看到的数据 知道什么是错的吗?

$ bundle exec rails s -p 3001
=> Booting WEBrick
=> Rails 4.2.5 application starting in development on http://localhost:3001
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2016-11-03 19:29:30] INFO  WEBrick 1.3.1
[2016-11-03 19:29:30] INFO  ruby 2.2.5 (2016-04-26) [x86_64-darwin15]
[2016-11-03 19:29:30] INFO  WEBrick::HTTPServer#start: pid=30949 port=3001

1 个答案:

答案 0 :(得分:1)

Completed 404 Not Found in 9ms (Views: 8.1ms | ActiveRecord: 0.0ms)

您的服务器和应用程序运行良好;您的浏览器正在http://localhost:3001完全正常加载页面。

问题是您的应用程序返回404 Not Found - 换句话说,Rails无法将控制器/操作与根路径匹配。

查看config/routes.rb文件。您应该为root定义路由,例如

root :to => 'home#index'

如果您正在直接访问路径(例如http://localhost:3001/example/path),请确保为此定义了路径:

get 'example/path', :to => 'controller#action'

最后,确保相关控制器存在,并为路线映射到的操作定义方法(例如,对于root示例,请确保app/controllers/home_controller.rb存在并且index方法定义)。