I am trying to use send_file to stream 1000 pictures on the browser, and simulate video streaming. I currently run my server (locally) using thin, and I have this in my controller:
send_file 'bg.jpg', :type => 'image/jpg', :disposition => 'inline'
I did not find any tutorials that explain send file, and I heard that I have to use ngnix to make it work. Any help streaming the pictures?
The page returns "Cannot read file bg.jpg", but the file is there, in the assets/images/ folder
Try
send_file 'assets/images/bg.jpg', :type => 'image/jpg', :disposition => 'inline'
Since send_file is not an assets method you will need to supply the full path to it.
Related
Im working with Yii, and I'am trying to put my controller into subdirectory.
It works when subdirectory is only 1 folder long :
Controllers / subdirectory / controller.php
But I'am forcing a problem when I want to have a path like this :
Controllers/ subdirectory / subdirectory2 / controller.php
In my urlManager I do everything analogically as it's for single nested way, but i get error :
The system is unable to find the requested action "subdirectory2"
So, it seems like Yii by defoult only understands in path the first subdirecotry as folder and second subdirecotry already considers as action, when i would like be the very last part's of url, so i could also work for longer paths.
Best.
It works in my way. Try to use this in your config file. Also there isn't problems with urlRewrite.
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'test' => 'directory/subdirectory/test/index'
),
),
this is my first time posting to stackoverflow. I am learning Ruby on Rails and i want to ask the reason why my app doesn't redirect to the root i specified in my routes.rb.
I already deleted the public/index.html and also removed it from git.
Jba::Application.routes.draw do
get "home/index"
root :to => 'home#index'
end
Thanks for helping. :)
Make sure you clear the cache on your local browser in order to view the changes you've made to your code.
I have switched over to pow in order to use ssl in development and I want to switch the host configuration in development, however devise continues to send email prefixed with the localhost:3000 domain. Here is what I have in my config/environments/development.rb file:
config.action_mailer.default_url_options = { :host => 'want_freight.dev' }
I have restarted my server and I have grepped my entire application looking for the offending use of localhost:3000 however my search turned up nothing outside of tmp and log files. Does anyone know why this would not be working??
I changed config.action_mailer.default_url_options to point to Pow's .dev URL, restarted my computer, and, against all odds, it was working again.
So I was able to have some success by adding :only_path => false to the default_url_options hash and using named urls, e.g. user_url( #user.id ) instead of link_to.
This problem was actually related to the devise_async gem causing conflicts with the mailer, I was able to resolve the issue by removing the gem from my gemfile.
No need to restart computer, just restart POW:
touch ~/.pow/restart.txt
I am new to rails and want to do a simple routing to root operation. My file path is app/views/slots/index.html.erb. When I go in my routes.rb file and see:
You can have the root of your site routed with "root"
just remember to delete public/index.html.
root :to => 'welcome#index'
I change the 'welcome#index' to "slots#index', I get this error from localhost:3000:
No route matches [GET] "/"
In the terminal, I use ctrl c to exit server and $ rails server to restart and still get the error. I watched my instructor do the same exact simple steps yet I get this error. Anyone know what I did wrong?
Edit : my bad, indeed the error is not corresponding to the solution I described below.
It seems you didn't create the slots controller.
You have to create a controller to display files. app/views/slots/index.html.erb is just a view, corresponding to an action of a controller.
So create the file app/controller/slots.rb
class SlotsController < ApplicationController
def index
end
end
You can do this faster with generator. In your terminal, cd to your application path and then
rails generate controller Slots index
To learn Rails I recommend you some reading here : http://guides.rubyonrails.org/getting_started.html
I am trying to use rack offline in rials to make my webpage available offline. By default rack offline takes all files from the public folder into the cache manifest. In which file should I make changes so that it will take the add the file that I want into the cache manifest. I want to include the file in my views folder.
You need to add it to your routes.rb file. Here is my routes.rb file with a customized manifest. This will give you the index and the new routes as well as all of the html files in your public root (*.html) and every file in a sub-folder to public (*/*.*). You can slice and dice that however you need it for stuff in the public folder.
I don't know how to get the database specific routes like show and edit while offline. I would imagine Javascript is needed. Check out Railscast episode 248 for some ideas for integrating JS
OfflineConfirm::Application.routes.draw do
#match '/application.manifest' => Rails::Offline
resources :contacts
offline = Rack::Offline.configure do
cache ["contacts/new", "contacts"]
public_path = Rails.root.join("public")
Dir[public_path.join("*.html"),
public_path.join("*/*.*")].each do |file|
p = Pathname.new(file)
cache p.relative_path_from(public_path)
end
network "/"
end
match '/application.manifest' => offline
end
The routes file above will produce the following application.manifest
CACHE MANIFEST
# 700ae3e3002382cb98b93c299d7b7bda151183b4703ef65d4c46b0ecf9c46093
contacts/new
contacts
404.html
422.html
500.html
index.html
images/rails.png
javascripts/application.js
javascripts/jquery.js
javascripts/jquery.min.js
javascripts/rails.js
stylesheets/scaffold.css
NETWORK:
/
None of the files in your views folder are available without a server. You want to make a route available in the cache manifest? For instance "/about", which corresponds to a "views/about.haml" file for instance?
Add this to your config:
offline = Rack::Offline.configure do
cache "about" # or whatever your route is
public_path = Rails.public_path
Dir[public_path.join("javascripts/*.js")].each do |file|
cache file.relative_path_from(public_path)
end
end