Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

ruby on rails - call javascript_include_tag within a rack middleware

I am building a rack middleware (to work within rails) that wants to use javascript_include_tag from within the rack middle ware.

How can I call javascript_include_tag outside of the controller/view context.

I guess even this title is a bit to detailed. All I want to do is get the correct link to some asset from within a rack middleware.

To put it at the highest level I can: Need to have rack middleware get the link to the sprockets generated asset for a given file.

Why? Well I guess that is my business, but its for a gem I maintain that creates a test page that you can then use rspec/capybara to interact with assets on that page. This allows unit testing of the assets without relying on the specific context on some layout or view.

Currently I provide this capability by having the gem dynamically create a controller, and then hacking around in the rails route. All works fine, but it just seems like its calling out for a simple rack middle ware that will handle the test url.

Also this means I have separate code to deal with non-rails environments (i.e. Sinatra) . It would be nice if the only dependency were sprockets and rack.

question from:https://stackoverflow.com/questions/65919939/call-javascript-include-tag-within-a-rack-middleware

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...