How do I configure my models to avoid their assets being deleted upon assets recompilation, when I push new code to Openshift?
At the moment my model looks like this:
class Slide < ActiveRecord::Base
attr_accessible :caption, :position, :visible, :photo
has_attached_file :photo, :styles => { :thumb => "190x90>" }
...
I have noticed that uploaded photos are deleted from /public directory when Openshift recompiles my assets upon pushing new code.
I have found some old code looking like this:
has_attached_file :attachment, :removable => true,
:url => "/attachments/:id/:style/:basename.:extension",
:path => ":rails_root/tmp/attachments/:id/:style/:basename.:extension"
Am I supposed to try something like in the above code snippet, or is there an option to change it in Openshift configuration?
The $OPENSHIFT_REPO_DIR structure will get replaced by your local git repo on every git push.
Best practice would be use $OPENSHIFT_DATA_DIR instead of $OPENSHIFT_REPO_DIR for handling uploads in your application.
For more details, please review: https://openshift.redhat.com/community/kb/kb-e1065-what-is-application-crud-and-how-should-i-handle-it-in-openshift
Related
I am using middleman-blog and middleman-deploy.
What I would like to do, is within the branch I am deploying to, I want the static files to be deployed to a subfolder within the repo (i.e. not the root folder).
I tried doing this in my config.rb:
activate :deploy do |deploy|
deploy.build_before = true
deploy.deploy_method = :git
deploy.branch = 'gh-pages-2'
deploy.remote = 'github'
deploy.path = 'blog'
end
But that doesn't work, it still deploys to the root directory. In fact, it doesn't even create the /blog folder I am looking for.
When I visit the config settings locally, these are the settings I see under :deploy:
:deploy
:branch = "gh-pages"
:build_before = true
:clean = false
:commit_message = nil
:deploy_method = :git
:flags = nil
:host = nil
:password = nil
:path = "blog"
:port = 22
:remote = "github"
:strategy = :force_push
:user = nil
This indicates to me that the path attribute is being set correctly.
I also tried doing deploy.path = '/blog' and that still doesn't work.
So how can I get this to deploy to \blog\ subfolder within my repo rather than the root directory?
The versions of the different gems are as follows:
middleman (4.1.10)
middleman-blog (4.0.1)
middleman-cli (4.1.10)
middleman-deploy (2.0.0.pre.alpha)
Note: I am purposely using gh-pages-2 because I don't want to overwrite my current gh-pages without being certain that it will deploy to the correct subfolder.
I think the easiest thing you could do is write an extension with an after build step: https://middlemanapp.com/advanced/custom-extensions/#after_build. That way you move the files during your build process and middleman-deploy just can push the whole build folder.
If the root of your site is also deployed on Github Pages you can create another repo called blog and deploy your middleman site there. Then by enabling GitHub Pages for the blog repo, you will actually have it deployed on yoursite.com/blog.
It is not the techiest solution you 'd expect but it works well for me
I am using paperclip gem for uploading. And i want to save the uploaded file/image outside of the public folder. If you have any idea please share.
Actually there is many. The 'public' option is just to be able to test easily. For your production server, paperclip gives three options:
File Storage
S3 Storage (via aws-sdk)
Fog Storage
File storage can be configured to go to any folder you want with something like:
config.paperclip_defaults = {
:path => "/yourfolder/:basename.:extension"
}
This can be overridden on the class itself if needed:
has_attached_file :avatar,
:path => "/yourotherfolder/:basename.:extension"
I have followed the Heroku guide on deploying static files using Ruby Rack (https://devcenter.heroku.com/articles/static-sites-ruby), but I was unable to access any HTML file in \public apart from index.html. Namely, localhost:9292/test.html still maps to index.html. (All my style and js files serve correctly).
Below is my config.ru file. I know what's wrong, but not sure about a valid solution?
use Rack::Static, :urls => ["/images", "/js", "/css"], :root => "public"
run lambda { |env| [
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=86400'
},
File.open('public/index.html', File::RDONLY) ] }
For your config.ru file, try:
use Rack::Static,
:urls => ["/images", "/js", "/css"],
:root => "public"
run Rack::File.new("public")
You could also replace the last line with run Rack::Directory.new("public") which would serve up all your files, but would give a file browser like interface if someone went to the url of a directory (like the root directory)
I have no Ruby experience and I found this boilerplate project helpful when trying to deploy a static website to Heroku:
heroku-static-site
Particularly, make sure you also have Gemfile and Gemfile.lock files besides the config.ru.
Author's project structure hosts everything in the root directory but you can easily move everything to public/ and correct the config.ru as #looby suggested.
I have a rails app with a folder rails.root/app/resources where I keep some library code.
This library code is used in a rack app that I mount in routes.rb in my Rails application
# rails.root/app/resources/file_resource.rb
# routes.rb
mount DAV4Rack::Handler.new(
:root => Rails.root.to_s,
:resource_class => FileResource
), :at => '/', :constraints => {:subdomain => "w"}
How can I make the FileResource reload on each request in development?
I tried autoload_paths, reload_plugin, none seem to work.
I think it has something to do with the code in routes.rb.
If I make a file rails.root/app/resources/my_helper.rb and use MyHelper.test() inside FileResource, the MyHelper gets reloaded.
No, I don't want to move this in 'lib' folder.
I am currently using the following hack, if anyone has a better solution please do share!
# config/environments/development.rb
root = config.root
config.to_prepare do
load "#{root}/app/resources/file_resource.rb"
end
I've just installed paperclip 2.3.3 and paperclipftp 0.1.0.
Paperclip was working fine, the attachments were saving and everything was great.
Enter paperclipftp.
I've included both gems in my Gemfile, installed it with bundle and made sure all dependencies were satisfied. I've also double checked that all my ftp info is correct and the server is working fine.
When I try to attach a file using ftp:
has_attached_file :photo,
:styles => {
:small => "204x159#",
:original => "460X370#"
},
:storage => :ftp,
:path => "/:attachment/:attachment/:id/:style/:filename",
:url => "http://kickassserver.com/_myfolder/:attachment/:attachment/:id/:style/:filename"
I get the following error:
Paperclip::StorageMethodNotFound in SetupsController#create
Cannot load 'paperclip/storage/ftp'
I'm thinking that paperclipftp isn't actually being loaded by my app. Is there a way I can check to see that it's actually being loaded, or has anyone else experienced this?
Thanks,
Matt
I have ruby 1.9.2p180 and the problem is that the timeout class being loaded.
Only add,
require 'timeout'
to the application.rb and this will fix your error.