Retain signature files and db images while migrating in rhodes rhomobile - ruby

I am using rhodes version 3.4.2, RMS 2.2.1.13 for building an application.
What I want is, when I am migrating to a newer build with some data migrations, I would like to keep all the image files and signature files from the previous build to be present.
The image files and signature files are being stored in the root directory of the app, and not the default db-files folder for rhomobile.
Right now, when I am trying to upload an image which was there in previous build from a new build,
I get the following error: Rho::AsyncHttp.upload_file: finished with error 26 failed to open/read local data from file.
Any Suggestion anyone?
Update with code:
result = Rho::AsyncHttp.upload_file(
:url => url,
:ssl_verify_peer => false,
:multipart => [
{
:filename => filePath,
:name => imageValuesJSON,
:content_type => imageHeader
},
{
:body => "",
:name => imageValuesJSON,
:content_type => imageHeader
}
]
)

Related

Hybridauth + composer: how to add custom providers

I'm converting a php project to use composer as dependency manager.
The dependencies are loaded via this line in my main script.
require 'vendor/autoload.php';
One of these dependencies is hybridauth (version 2.9). Since using Composer, it throws 'file not found' errors when looking for custom providers files.
For instance, my main controller calls Hybrid like this:
$config_file_path = dirname(__FILE__) .'/hybridauth/config.php';
$hybridauth = new Hybrid_Auth( $config_file_path );
Now, here is the config file. The provider i'm using is "Facebooktest".
Note that I had to specify the path via the [wrapper][path]; array key to get to the next error message.
return
array(
"base_url" => WWWROOT."/auth",
"providers" => array(
"Facebook" => array(
"enabled" => true,
"keys" => array("id" => "xxxxxxx", "secret" => "xxxxxxxx"),
"scope" => "email",
"trustForwarded" => false
),
"Facebooktest" => array(
"enabled" => true,
"keys" => array("id" => "xxxxxxx", "secret" => "xxxxxx"),
"scope" => "email",
"trustForwarded" => false,
"wrapper"=> array(
"class"=>'Hybrid_Providers_Facebooktest',
"path"=> './controllers/hybridauth/Hybrid/Providers/Facebooktest.php'
)
)
),
"debug_mode" => false,
"debug_file" => "",
);
The error message (with trace):
require_once(/path/to/composer-project/vendor/hybridauth/hybridauth/hybridauth/Hybrid/thirdparty/Facebook/autoload.php): failed to open stream: No such file or directory
[vendor/bcosca/fatfree/lib/base.php:2174] Base->error()
[controllers/hybridauth/Hybrid/Providers/Facebooktest.php:61] Base->{closure}()
[controllers/hybridauth/Hybrid/Providers/Facebooktest.php:61] require_once()
[vendor/hybridauth/hybridauth/hybridauth/Hybrid/Provider_Model.php:99] Hybrid_Providers_Facebooktest->initialize()
[vendor/hybridauth/hybridauth/hybridauth/Hybrid/Provider_Adapter.php:101] Hybrid_Provider_Model->__construct()
[vendor/hybridauth/hybridauth/hybridauth/Hybrid/Auth.php:278] Hybrid_Provider_Adapter->factory()
[vendor/hybridauth/hybridauth/hybridauth/Hybrid/Auth.php:230] Hybrid_Auth::setup()
[controllers/auth-action.get.php:19] Hybrid_Auth::authenticate()
I find it strange that I now need to modify paths inside the "vendor/hybridauth/" project. It defeats the purpose of using a dependency manager. Surely, I must be doing it wrong.
Can you advise?
Check my answer to another question here
If you have recently installed Hybridauth through composer you probably have downloaded v2.9.2, which contain a bug in their Facebook class that replace the vendor path from yours to hybridauth/vendor, causing such issue.
I suspect you created that Facebooktest class by copying their Facebook class and therefore sustained that error. Either update to their dev branch and copy that Facebook class, or simply use other provider class as template for your custom provider class.

convert embedded ruby file to PDF file instead of only HTML file using Rails 3

I want to convert my embedded ruby file to PDF file after clicking on a link using Rails 3.I became able to convert simple html file to PDF file using pdfkit gem.I am explaining my code below.
users_controller.rb:
class UsersController < ApplicationController
def index
end
def download_pdf
#html = render_to_string(:action => "/users/download_pdf.html.erb")
#kit = PDFKit.new('http://google.com')
#kit = PDFKit.new(html)
#send_data(kit.to_pdf, :filename => 'report.pdf', :type => 'application/pdf', :disposition => 'inline')
kit = PDFKit.new("<h1>Hello</h1><p>This is PDF!!!</p>", :page_size => "A4")
send_data(kit.to_pdf, :filename => 'report.pdf', :type => 'application/pdf', :disposition => 'inline')
#file = kit.to_file('my_file_name.pdf')
end
end
In this controller page i did and got success to convert from HTML to PDF.
users/index.html.erb:
<p>
<%= link_to "Download pdf",download_pdf_path(:format => 'pdf') %>
</p>
When user will click on the above "download_pdf" link the download.html.erb will convert to PDF file and it should display as well as download in specified folder.The download.html.erb file is given below.
users/download.html.erb:
<h1>Hello Rails</h1>
The above file should convert into PDF file with proper css .If i have css for this like below.
application.css:
h1{
width:100px;
height:100px;
background-color:red;
}
How can i include this CSS in that PDF file.My other files are given below.
pdfkit.rb:
PDFKit.configure do |config|
#config.wkhtmltopdf =Rails.root.join('bin', 'wkhtmltopdf-i386').to_s
config.wkhtmltopdf='C:/wkhtmltopdf/bin/wkhtmltopdf.exe'
#config.default_options[:ignore_load_errors] = true
end
Please help me to resolve this issue and make this successfully.
By using wicked_pdf gem i am getting the following error.
error:
RuntimeError in UsersController#download_pdf
Error: Failed to execute:
["C:/wkhtmltopdf/bin/wkhtmltopdf.exe", "file://C:/DOCUME~1/SUBHRA~1/LOCALS~1/Temp/wicked_pdf20150527-3204-calx6j.html", "C:/DOCUME~1/SUBHRA~1/LOCALS~1/Temp/wicked_pdf_generated_file20150527-3204-59mbli.pdf"]
Error: PDF could not be generated!
Command Error: Loading pages (1/6)
[> ] 0%
[======> ] 10%
Error: Failed loading page file://c/DOCUME~1/SUBHRA~1/LOCALS~1/Temp/wicked_pdf20150527-3204-calx6j.html (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: ContentNotFoundError
check the below code for this gem.
users/users_controller.rb:
class UsersController < ApplicationController
def index
end
def download_pdf
render pdf: 'test',
layout: '/layouts/test',
template: '/users/test',
handlers: [:erb],
formats: [:pdf],
:save_to_file => Rails.root.join('public', "test.pdf")
end
end
wicked_pdf.rb:
WickedPdf.config = {
#:wkhtmltopdf => '/usr/local/bin/wkhtmltopdf',
#:layout => "pdf.html",
:exe_path => 'C:/wkhtmltopdf/bin/wkhtmltopdf.exe'
}
You can include your stylesheets by following:
def download_pdf
kit = PDFKit.new(File.open(Rails.root.join('app', 'views', 'users', 'download.html.erb')))
kit.stylesheets << Rails.root.join("app","assets","application.css")
send_data(kit.to_pdf, :filename => 'report.pdf', :type => 'application/pdf', :disposition => 'inline')
end

Upload comfortable mexican sofa cms image's to heroku from s3 bucket

I had successfully integrated comfortable mexican sofa CMS into an existing rails 4.1.2 application.
Now I want to upload images to heroku from s3 bucket.
Can anyone please tell the steps for that?
Sofa is using paperclip for attachments. So first, take a look here: http://www.rubydoc.info/gems/paperclip/Paperclip/Storage/S3
Then in initializers/comfortable_mexican_sofa.rb you'll find config.upload_file_options. This is how you'll override defaults.
config.upload_file_options = {
:storage => :s3,
:s3_credentials => ...
}
config.upload_file_options = {
:whiny => false,
:storage => :s3,
:s3_credentials => {"access_key_id" => ENV["S3_ACCESS_KEY_ID"], "secret_access_key" => ENV["S3_SECRET_ACCESS_KEY"]},
:bucket => ENV["S3_BUCKET_NAME"],
:s3_host_name => 's3 HOST NAME',
:path => "uploaded_files/:basename.:extension",
:styles => {:thumb => "850x850>" }
}
Give styles inside the config.upload_file_options which will take exact size of an image.
Which make more sense in uploading image else image pixels may vary.
The available configuration parameters are defined in paperclip, not comfy, and more information about there meaning can be found at:
http://www.rubydoc.info/github/thoughtbot/paperclip/Paperclip/Storage/S3
Just a note: Comfy has switched from Paperclip to ActiveStorage in 2017, so the answers are somewhat outdated.

How can I upload files to Redmine via ActiveResource / REST API?

I am trying to batch-upload images to Redmine and link them each to a certain wiki pages.
The docs (Rest_api, Using the REST API with Ruby) mention some aspects, but the examples fail in various ways. I also tried to derive ideas from the source - without success.
Can anyone provide a short example that shows how to upload and link an image from within Ruby?
This is a bit tricky as both attachments and wiki APIs are relatively new, but I have done something similar in the past. Here is a minimal working example using rest-client:
require 'rest_client'
require 'json'
key = '5daf2e447336bad7ed3993a6ebde8310ffa263bf'
upload_url = "http://localhost:3000/uploads.json?key=#{key}"
wiki_url = "http://localhost:3000/projects/some_project/wiki/some_wiki.json?key=#{key}"
img = File.new('/some/image.png')
# First we upload the image to get attachment token
response = RestClient.post(upload_url, img, {
:multipart => true,
:content_type => 'application/octet-stream'
})
token = JSON.parse(response)['upload']['token']
# Redmine will throw validation errors if you do not
# send a wiki content when attaching the image. So
# we just get the current content and send that
wiki_text = JSON.parse(RestClient.get(wiki_url))['wiki_page']['text']
response = RestClient.put(wiki_url, {
:attachments => {
:attachment1 => { # the hash key gets thrown away - name doesn't matter
:token => token,
:filename => 'image.png',
:description => 'Awesome!' # optional
}
},
:wiki_page => {
:text => wiki_text # original wiki text
}
})

Rails3 mailer with image_tag ignoring host

I've got a Rails3 mailer layout that include images.
This ones are used like :
image_tag("emails/top.gif", :width => "700", :height => "10", :alt => "")
As of Rails 2, this images included the host and produced the expected result. However, since Rails3 the config.action_mailer.default_url_options seems to be ignored.
Is there anything I'm missing?
Update
my config/environment/development.rb include:
config.action_mailer.default_url_options = { :host => 'mydomain.tld' }
Needs to use config.action_mailer.asset_host = 'http://mysite.com' in your environment config file
Credits: wmoxam in #rubyonrails

Resources