簡體   English   中英

Hyperstack找不到登錄頁面資源

[英]Hyperstack doesn't find landing page resource

超文本/安裝指南顯示了如何將超文本添加到現有的Rails應用程序。 我已經到了可以像以前那樣啟動舊版應用程序的地步,但是無法解析圖像資源的路由。 我想我只是沒有正確設置路線,另一方面,我從指南中所講的內容都沒有改變。 這是Hyperstack的第一步,它看起來很明顯,但是並沒有屈服於我到目前為止嘗試過的簡單測試。

routes.rb

    Rails.application.routes.draw do

    mount Hyperstack::Engine => '/hyperstack'  # this route should be first in the routes file so it always matches

/hyperstack/hyper_component.rb

# app/hyperstack/hyper_component.rb
class HyperComponent
  # All component classes must include Hyperstack::Component
  include Hyperstack::Component
  # The Observable module adds state handling
  include Hyperstack::State::Observable
  # The following turns on the new style param accessor
  # i.e. param :foo is accessed by the foo method
  param_accessor_style :accessors
end

/components/shipment.rb

class Shipment < HyperComponent

  # param :my_param
  # param param_with_default: "default value"
  # param :param_with_default2, default: "default value" # alternative syntax
  # param :param_with_type, type: Hash
  # param :array_of_hashes, type: [Hash]
  # other :attributes  # collects all other params into a hash
  # fires :callback  # creates a callback param

  # access params using the param name
  # fire a callback using the callback name followed by a !

  # state is kept and read as normal instance variables
  # but when changing state prefix the statement with `mutate`
  # i.e. mutate @my_state = 12
  #      mutate @my_other_state[:bar] = 17

  # the following are the most common lifecycle call backs,
  # delete any that you are not using.
  # call backs may also reference an instance method i.e. before_mount :my_method

  before_mount do
    # any initialization particularly of state variables goes here.
    # this will execute on server (prerendering) and client.
  end

  after_mount do
    # any client only post rendering initialization goes here.
    # i.e. start timers, HTTP requests, and low level jquery operations etc.
  end

  before_update do
    # called whenever a component will be re-rerendered
  end

  before_unmount do
    # cleanup any thing before component is destroyed
    # note timers are broadcast receivers are cleaned up
    # automatically
  end

  render do
    DIV do
      'Shipment'
    end
  end
end

從命令行開始

$ bundle exec foreman start
...
ActionView::Template::Error (couldn't find file 'client_and_server-e8a2a4c02f7542e3e05c' with type 'application/javascript'
...

然后在命令行中

/Users/john/.rvm/gems/ruby-2.6.2/gems/bootstrap-4.3.1/assets/stylesheets
16:45:00 web.1        |   /Users/john/.rvm/gems/ruby-2.6.2/gems/bootstrap-4.3.1/assets/javascripts):
16:45:00 web.1        |     10: 
16:45:00 web.1        |     11:  
16:45:00 web.1        |     12:   // search path default is public/images
16:45:00 web.1        |     13:   = image_tag "Drayage-LongBeach.jpg", :size => "520x360" 
16:45:00 web.1        |     14:   %p
16:45:00 web.1        |     15:   %p
16:45:00 web.1        |     16: 

基於它找不到您的打包清單文件的事實(我假設以前曾在此工作),我懷疑您使用的是webpacker <4.0。

Webpacker現在將捆綁軟件存儲在/javascripts/js而不僅僅是/javscripts/ ,而超級堆棧安裝程序會假定這樣做。

保持Webpack的當前版本

進入config/initializers/assets.rb ,您將在最后看到這樣的一行

Rails.application.config.assets.paths << Rails.root.join('public', 'packs', 'js').to_s

只需刪除, 'js' ,它將與舊的webpacker一起使用。

config/environments/test.rb中也有類似的行,也需要對其進行修改以使超規格正常工作。

升級Webpack(推薦-您遲早要這樣做)

或者,您可以將webpacker升級到〜> 4.0。

您需要為兩個沖突都回答“ Y”,然后還必須刪除.babelrc文件(如果存在),最后運行bin/webpack

  1. 更新您的Gemfile
  2. bundle install
  3. bundle exec rails webpacker:install 對兩個沖突都 bundle exec rails webpacker:install 答案Y
  4. 刪除.babelrc如果存在)
  5. 運行bin/webpack

這應該可以將webpacker成功升級到4.x,並且現在一切都應該很好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM