Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 我们可以为rails应用程序应用破折号吗_Ruby On Rails_Ruby On Rails 3_Ruby On Rails 3.1_Sinatra - Fatal编程技术网

Ruby on rails 我们可以为rails应用程序应用破折号吗

Ruby on rails 我们可以为rails应用程序应用破折号吗,ruby-on-rails,ruby-on-rails-3,ruby-on-rails-3.1,sinatra,Ruby On Rails,Ruby On Rails 3,Ruby On Rails 3.1,Sinatra,现在我正在处理dashing,从这里开始,我使用Sinatra创建了一个dashing应用程序,并添加了一些第三方API,一切正常。现在我想用rails运行这个应用程序,我试过了,一切都正常,但服务器无法调用“event”方法 require 'sinatra' ``require 'sprockets' require 'sinatra/content_for' require 'rufus/scheduler' require 'coffee-script' r

现在我正在处理dashing,从这里开始,我使用Sinatra创建了一个dashing应用程序,并添加了一些第三方API,一切正常。现在我想用rails运行这个应用程序,我试过了,一切都正常,但服务器无法调用“event”方法

require 'sinatra'
   ``require 'sprockets'
   require 'sinatra/content_for'
   require 'rufus/scheduler'
   require 'coffee-script'
   require 'sass'
   require 'json'
   require 'pry'

 module Dashing
  SCHEDULER = Rufus::Scheduler.start_new

  class App < Sinatra::Base
    if Rails && Rails.root
      set :root, Rails.root
      set :root_path, '/dashing/'



      Rails.application.config.assets.precompile += %w( dashing/application.js dashing/application.css )
      set :views, Rails.root.join('app', 'dashing', 'dashboards')
      set :widget_path, "#{settings.root}/app/dashing/widgets/"

      set :lock, true
      set :threaded, true
    else
      set :root, Dir.pwd
      set :root_path, '/'

      set :sprockets,     Sprockets::Environment.new(settings.root)
      set :assets_prefix, '/assets'
      set :digest_assets, false
      ['assets/javascripts', 'assets/stylesheets', 'assets/fonts', 'assets/images', 'widgets', File.expand_path('../../javascripts', __FILE__)]. each do |path|
        settings.sprockets.append_path path
      end

      set server: 'thin'
      set :public_folder, File.join(settings.root, 'public')
      set :views, File.join(settings.root, 'dashboards')
      set :widget_path, File.join(settings.root, 'widgets')
    end

    set connections: [], history: {}
    set :default_dashboard, nil
    set :auth_token, nil

    helpers Sinatra::ContentFor
    helpers do
      def protected!
        # override with auth logic
      end
    end

    get '/events', provides: 'text/event-stream' do
      protected!
      stream :keep_open do |out|
        settings.connections << out
        out << self.latest_events
        out.callback { settings.connections.delete(out) }
      end
    end

    get '/' do
      begin
      redirect settings.root_path + (settings.default_dashboard || self.first_dashboard).to_s
      rescue NoMethodError => e
        raise Exception.new("There are no dashboards in your dashboard directory.")
      end
    end

    get '/:dashboard' do
      protected!
      erb params[:dashboard].to_sym
    end

    get '/views/:widget?.html' do
      protected!
      widget = params[:widget]
      send_file File.join(settings.widget_path, widget, "#{widget}.html")
    end

    post '/widgets/:id' do
      request.body.rewind
      body =  JSON.parse(request.body.read)
      auth_token = body.delete("auth_token")
      if !settings.auth_token || settings.auth_token == auth_token
        Dashing::Application.send_event(params['id'], body)
        204 # response without entity body
      else
        status 401
        "Invalid API key\n"
      end
    end

    class << self
      def development?
        ENV['RACK_ENV'] == 'development'
      end

      def production?
        ENV['RACK_ENV'] == 'production'
      end

      def send_event(id, body)
        body["id"] = id
        body["updatedAt"] = Time.now.to_i
        event = format_event(body.to_json)
        settings.history[id] = event
        settings.connections.each { |out| out << event }
      end

      def format_event(body)
        "data: #{body}\n\n"
      end
    end

      def latest_events
        settings.history.inject("") do |str, (id, body)|
          str << body
        end
      end


    def first_dashboard
      files = Dir[File.join(settings.views, '*.erb')].collect { |f| f.match(/(\w*).erb/)[1] }
      files -= ['layout']
      files.first
    end

    Dir[File.join(settings.root, 'lib', '**', '*.rb')].each {|file| require file }
    {}.to_json # Forces your json codec to initialize (in the event that it is lazily loaded). Does this before job threads start.

    job_path = ENV["JOB_PATH"] || 'jobs'
    files = Dir[File.join(settings.root, job_path, '/*.rb')]
    files.each { |job| require(job) }
  end
end 
需要“sinatra”
``需要“链轮”
需要“sinatra/content\u for”
需要“rufus/scheduler”
需要“咖啡脚本”
要求“无礼”
需要“json”
需要“窥探”
模块缓冲
SCHEDULER=Rufus::SCHEDULER.start\u新建
类应用程序settings.connections您可能想看看它只适用于rails 4
要求

Ruby>=1.9.3 轨道4 雷迪斯
多线程服务器(puma,rainbows)

是的,我建议为DashRails创建一个rails 4应用程序,并从rails 3应用程序发送redis事件。