Гипертекст / руководство по установке показывает, как добавить гипертекст в существующее приложение 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
/ компоненты / 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: