Rectangle 27 3

I hope you are rendering the HTML string to generate some PDF / kind of files. In those case, we need to declare the instance variable from where your are invoking those calls. So that it can be accessed through out the request. (Same mailer concepts)

def generate_attachment(your_variable)
    @your_instance_variable = your_variable

    attachments['attachment.pdf'] = => "filename.pdf",:template => '/_template.html.erb'))

ruby on rails - Generate PDF by binding erb template that contains ins...

ruby-on-rails ruby erb
Rectangle 27 2

You can modify your Namespace#initialize method so that it assigns instance variables instead of defining instance methods for each key of your hash:

class Namespace
  def initialize(hash)
    hash.each do |key, value|
      instance_variable_set(:"@#{key}", value)

  def get_binding

ns = 'Joan', address: 'Chennai, India')
#=> #<Namespace:0x007feca2400e98 @address="Chennai, India", @name="Joan">
#=> "<h1>Name: Joan<h1>\n<h2>Address: Chennai, India<h2>"

ruby on rails - Generate PDF by binding erb template that contains ins...

ruby-on-rails ruby erb
Rectangle 27 0

I think that you need to add the physical path to the PDF file for it to work (otherwise it may not know where the file is). This post on a forum says as follows:

The only problem is that this "mailto" command executes on the client machine, therefore it tries to locate the attachment file by a physical path, and not by a virtual path.

works ok, but only for local users (those connected to the same network as the "myhost" machine).

does not work, it does not recognize such a syntax as valid for the attachment file.

In your case you would properbly need to look at this part of the Rhomobile docs (on file system access) to get the right path to your file.

From you comment I can see that you are trying to make it work on iOS (due to the iOS specific path).

In this discussion (from Rhomobile's Google Group) it is explained that mailto doesn't support attachments on iOS. It says as follows:

Don't know about other platforms, but you cannot do this on iOS. mailto: does not support attachments on iOS.

You can do it using a native API, MFMailComposeViewController.

This is a complete controller with UI, so you would have to write a Native View Extension to use it:

I've looked around and it seems that mailto doesn't support attachments on Android either. This is because Android supports the RFC 2368 mailto protocol, which doesn't include attachments. Here is a reference to the Android mailto url parser.

I would suggest that you do as suggested for iOS, write a native extension. I think this post would be relevant for you.

I am giving the complete path but it isnt working. Code is like: <% fileNameW = File.join(Rho::RhoApplication::get_user_path(), 'demo.pdf')%> <a href="mailto:<%=@user.mgremail%>?subject=Expense Report&attachment='<%=fileNameW%>'">Mail to Manager</a>

Couldn't figure out what made you think i am doing this for ios. I am developing an Android app on Rhomobile.

As far as I can see, the 'Rho::RhoApplication::get_user_path' is iOS specific. It is only mentioned under "Rhodes client file system structure on iOS platform" in the Rhodes documentation. Maybe that is your problem ?

It is working for me at other places as well. Still i tried giving the static path as well but neither it returns any error nor it recognizes the attachment. Do you know any other alternative for this?

ruby - Send Email with pdf file as attachment in rhomobile - Stack Ove...

ruby email pdf email-attachments rhomobile
Rectangle 27 0

You can actually use Wicked-PDF directly without the controllers by:

<h1>Hello There!</h1>
  render_to_string('templates/pdf.html.erb', :layout => 'pdfs/layout_pdf'),
  :footer => {
    :content => render_to_string(:layout => 'pdfs/layout_pdf')
) # which is awesome

khaled-gomaa - how would you save that generated pdf onto the disk? Let say I will generate it in a controller as you have sugested pdf = Is {...} the way to go? I know you have suggested sidekiq for pdf generation. How would I save it then if the controller quits straight after. My sidekiq knowledge is limited. It is probably another question but if you could update your answer with this info I will appreciate it.

ruby on rails - Creating pdf and sending it via email - Stack Overflow

ruby-on-rails pdf-generation wicked-pdf
Rectangle 27 0

In Ruby the File.New() method creates a file in the current working directory of your program. To find the current working directory you can do

That will give you the directory path and if you append the filename to this then you have the full path of your file. To check if the dynamic file path that you've constructed is valid you can check if your file exists, with

Once you have the path of your dynamic file you can read those file bytes and put them into your DocuSign API request. The DocuSign API doesn't care where the bytes come from as long as they are valid file bytes encoded correctly.

ruby on rails 3 - Docusign_rest how to send custome pdf as parameter -...

ruby-on-rails-3 rest pdf prawn docusignapi
Rectangle 27 0

Okay I stepped away for a moment and came back and googled a little more and got the answer!

Implicit template rendering is not performed if any attachments or parts have been added to the email. This means that youll have to manually add each part to the email and set the content type of the email to multipart/alternative.

For the main mailer method I switched out body and added this explicit render. Note- I skipped the multipart/alternative and it worked, most likely because I am sending a plain text email.

part        :body => render_message('auto_response', :recipient => lead.first_name)

For the attachment naming issue, this is what I did:

attachment  "application/pdf" do |a|
                a.body = + "/public/files/OtherSheet.pdf") 
                a.filename = "Othersheet.pdf"  

Did this work for you? does the file need to physically reside there? I generate my pdf's but don't save them.

ruby on rails - ActionMailer problem- what is the correct syntax for s...

ruby-on-rails actionmailer
Rectangle 27 0

file = temp.path, 'r') do |f|
   send_data'BINARY'), :filename => filename, :type => "application/pdf", :disposition => "attachment"

ruby - send PDF with rails send_data - Stack Overflow

ruby-on-rails ruby redmine
Rectangle 27 0

Funny, thought that i tried the include which unixMonkey recommend. Now I tried again and it works with following code... Thank you for pushing me into the right direction.

class WelcomeMailer < ApplicationMailer
      include PdfHelper

      def new_customer(user)
         @user = user

         test = render_to_string_with_wicked_pdf(
          pdf: "test.pdf",
          template: "pdf_templates/abc.html",
          header: {html: {template: "pdf_templates/header.html"}}

         attachments["abc.pdf"] = test
         mail to:, subject: "blaa blubb"

On my first try I didn't had pdf: "test.pdf". if you remove this it will not work.

ruby on rails - Generating and sending PDF in ActionMailer with Wicked...

ruby-on-rails pdf wicked-pdf