I recently began programming and learning Ruby and JavaScript and was attempting to read my html file through my Sinatra server using a config.ru file.
The server runs, its hitting all the routes but I think there may be something wrong with the server code for the index page:
get("/") do
content_type :html
File.read( File.expand_path("../views/index.html", __FILE__) )
end
Put index.html in public folder. Sinatra will serve files in public as is. So you need to request it directly e.g. http://localhost/index.html.
If you want to handle empty route i.e. get '/' use snippet below (from here):
get '/' do
send_file File.join(settings.public_folder, 'index.html')
end
In order to be sure in settings.public_folder please check does it work correctly, does it return correct path.
Cheers!
Related
One controller uses the styles of another controller, although they are not connected.
I generated "controller1" with "index1.html" and "controller2" with "index2.html", for "controller1" with "index1.html" I create the file "controller1.css" in the directory "/home/username/testApp/app/assets/stylesheets/controller1/controller1.css",
for "controller2" with "index2.html" I create the file "controller2.css" in the directory "/home/username/testApp/app/assets/stylesheets/controller2/controller2.css".
BUT CONTROLLER 2 USE STYLES FROM CONTROLLER 1, even if I don't connect them with tag "link" to index2.html.erb. HOW TO FIX THIS.
my routes.rb file, maybe it because that controller 1 is root, and controller 2 get??
Rails.application.routes.draw do
get 'controller2/index2'
root 'controller1#index1'
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
# Defines the root path route ("/")
# root "articles#index"
end
Please help me! Thank you!
I'm really new in VueJS,
I use RxJS, Vue rx and Vue Resource in a mixin so i can make http calls and get observables back anywhere... awesome!
now i tried
subscriptions () {
return {
titles$: this.getHTTPObservable('https://jsonplaceholder.typicode.com/albums').flatMap(arr => Rx.Observable.from(arr).take(10).map(o => o.title).toArray())
}
The only thing i need now is to specify the end point of the server i am requesting in some configuration file like i would do in angular environments file. When launching the build by hand it should look like when i write
ng serve --env=dev
is there something similar?
Actually i found the answer on this page https://vuejs-templates.github.io/webpack/env.html
so, i can add any configuration variable and then call process.env.varname to get it back,
thanks
Vue.js normally works in conjunction with Webpack to achieve this.
https://v2.vuejs.org/v2/guide/deployment.html#With-Build-Tools
The DefinePlugin from Webpack is used for this. Outside of Webpack I think you are still able to use this:
https://www.npmjs.com/package/cross-env
We're using Ruby on Rails 5.0.0.1 in API-Mode. What Middleware and Configurations do I need to add, in order to being able to render html instead of json in an controller.
Edit:
Thank you all for your answers.
Want I wanted is to render normal erb/haml views. not html in json like 'kartik upadhyay' mentioned. Since the Application is primary an JSON API we didn't want the full blown default Rails Installation, which mean our Application Controller extends from ActionController::API.
My Plan was to make a PdfRendering Controller which includes all Modules needed for ActionView to work. What I rather did was reading the asset pipeline (because we wanted to use sass) and inherit the application controller from ActionController::Base. as other rails apps would do.
It's not the nicest solution since you're including the whole ActionController::Base and all of it's Feature that you may not be using. But it's still slimmer that a full Blown Rails installation (especially the middleware aka. sessions etc.)
include ActionView::Layouts
include ActionController::Rendering
Add these to your controller
You can use render to string method of rails for rendering your html as string inside json, put this inside your controller:
render json: { data: render_to_string('html_file_name') }
this will render html as response like:
{"data": "<html>\n<h3>hello</h3>\n</html>"}
you can render erb/haml/slim etc. files like the following:
format.html { render :file_name }
You can simply use this gem RABL.
https://github.com/nesquena/rabl
I am trying to use jruby + page-object gem + Cucumber for a proof of concept. I used the following statement.
app_url = 'https:\\google.com'
page_url(app_url)
I get a
NoMethodError: undefined method `page_url' for #
However,
navigate_to(app_url)
works fine. page_url works fine in Ruby.
Is this the way this works in jRuby? Though navigate_to works, is this any different?
Thank you for your help!
page_url is a class method provided by including the PageObject module. It sets the url for the page so you can use the visit_page factory in your test:
object MyPage
include PageObject
page_url "http://example.com/"
end
In a test somewhere:
visit_page MyPage do |page|
page.some_object_element.do_something
end
navigate_to is browser functionality exposed directly in your test via some World magic.
I am busy testing a new approach to managing a java application that uses logback on a puppet-managed host, and was wondering if anyone had some advice on the best approach for this. I am stuck with a catch 22 situation.
The java application is deployed to a host by an automated system (CI). The deployment writes an application version number to a file (e.g. /etc/app.version may contain "0001")
The logback config file (logback.xml) is managed by puppet.
I am trying to configure the application to include it's version number in the logging layout (e.g. <pattern>VERSION: %version%</pattern> . However, I am not sure on the approach, as there isn't an "include" function for the logback config file (to include a file with the version number into the logback config). At the same time, I don't see a way to get puppet to do a client-side template build, using the host-side file (I've tried using a template approach, but the template is compiled on the puppet server side).
Any idea's on how to get this working?
I would write a custom fact. Facts are executed on the client.
Eg:
logback/manifests/init.pp
file { '/etc/logback.xml':
content => template('logback/logback.xml.erb')
}
logback/templates/logback.xml.erb
...
<pattern>VERSION: <%= scope.lookupvar('::my_app_version') %></pattern>
...
logback/lib/facter/my_app_version.rb
Facter.add('my_app_version') do
setcode do
begin
File.read('/etc/app.version')
rescue
nil
end
end
end
Hope that helps. I think in Puppet < 3.0 you will have to set "pluginsync = true" in puppet.conf to get this to work.