Attach document to a contact form in rails 3.2 - ruby-on-rails-3

I have created a contact form which will email me once sent. Now I need to be able to have the option of attaching a document that will be emailed to me also. i dont need to save it in a db as it will be with the email and downloaded from there.
Im new to rails so would like to see what other people have done in this situation, ive done some reading and see that i will need the gem paperclip in most instances? Also i have looked at jquery/paperclip in github but this seems a lot of work for what i hope is a small piece of work? I could be wrong here mind, so apologies if i am
Any help greatly appreciated

What you would have to do is use carrierwave gem or paperclip gem to upload the file to a specified folder in your public directory. I would do this using ajax that will allow you to upload the file instantly once you select the file to be sent. This would allow you to upload the attachment and have the file path known and ready so when you click submit, the following code will execute allowing you to send the file. You can also add a line of code to delete the file after it sent successfully if you don't want to accumulate files on your server. More documentation can be found here..
http://guides.rubyonrails.org/action_mailer_basics.html#sending-emails-with-attachments
class ApplicationMailer < ActionMailer::Base
def welcome(recipient)
attachments['free_book.pdf'] = File.read('path/to/file.pdf')
mail(:to => recipient, :subject => "New account information")
end
end

Related

Document upload (doc, docx, odt, etc.) and display in Rails (as text)?

Does anybody know how to upload a document to later show in a Rails application (as text)? Is Paperclip the right gem to do this? If it is how? (I have uploaded images before with Paperclip).
I like Paperclip. It seems well documented, and has worked well for everything I have needed. (I don't personally know any of them, but the clever folks at Thoughbot have created some pretty useful stuff, for which I feel indebted to them).
Obviously, you need to add Paperclip to your Gemfile, and (if you are using bundler) do your bundle install
Add to your model
has_attached_file :aFile
Add to you controller something to catch whatever you name it in your view (probably in your create and update methods)
#profile.aFile = params[:profile][:aFile]
Probably should check for its existence, if it is a required param
if params[:profile][:aFile].blank?
redirect_to #profile
else
render :action => 'do_something_interesting_with_file'
end
And that's about it. Don't forget your config entries. For example, if you are using some kind of post-processing on the file
Paperclip.options[:command_path] = "/opt/local/bin/"
I found this to be extraordinarily helpful
RailsCast by Ryan Bates

How to do Devise reset password mail customization?

i m using devise for authentication purpose, for reset password its send email like bellow
Hello there,
if you would like to reset or if you have forgotten your password please click on the following link: click_here
Thank you and happy bantering!
the swagata#gmail.com Regards
i want last line looks like
regards
the swagata#gmail.com
please give me some suggestion
You can customize the devise views. Run the following command in your project directory:
rails g devise:views
This will copy devise views (including mailer templates) in your app/views/devise directory. Then you can customize as you want.

ActionMailer sending emails with empty body

It appears that around the time that I upgraded rails to 3.2.8, the body isn't being set when I create and send emails. No code around the mailers has changed in this time, with the exception of ActionMailer also upgrading to 3.2.8.
I have beta_request_mailer.rb in app/mailers with the following method:
def beta_request(request)
mail(
:to => "#{request[:name]} <#{request[:email]}>",
:subject => 'Thanks for requesting an invite to xxxxx!'
)
end
I also have a body file which worked fine: app/views/beta_request_mailer/beta_request_email.html.erb
The email is being sent fine, just without any body. Running in the console, the mail object that's created in beta_request has no body when running mail.body. If I set a body manually, that gets sent out.
What's changed that I'm not aware of?
I was also getting emails that arrived ok and with the correct subject, but with no content in the mail and found that using the .deliver! instead of just .deliver method cured the problem (though don't know why)
Fixed by removing _email from file name
My solution was very interesting.
Firstly my Rails 4 application throw an error without layout file for mailer.
The I've created blank layout file mailer.html.slim. This resulted in mails delivered but without content.
Solution was to add ==yield inside mailer.html.slim
Works like charm. Hope this was your issue and this helped you.

typo3 file saving from backen with dynamic path

I have to save some posts with images. i create a directory for each post and save images there, but in backend if i edit/save the post the relation between images and post dies, any ideea how can i configure the saving path for the backend?
thanks anticipated.
i guess you forgot to set the directory also in file: ext_emconf.php
its not done when only creating the dir in the extension itself. this maybe is your (or typo3) problem
go into file: ext_emconf.php: and edit the array 'createDirs' => '

Multi-step form in Rails 3 with Paperclip attachments

I'm creating a multi-part form in the style that Ryan Bates describes here:
http://railscasts.com/episodes/217-multistep-forms
http://asciicasts.com/episodes/217-multistep-forms (text-based version)
To summarize, I have one view (with a bunch of partials for each form step), and the form variables are stored in a session when the user clicks a next button and a different part of the form is displayed.
One of my form steps allows the user to upload several images via the Paperclip gem. The problem with that is that Rails is trying to upload the image data to the session, which is returning TypeError "can't dump File".
What is a good way to go about this?
UPDATE:
I've tried a bunch of gems (wizardly, acts_as_wizard, and some other smaller ones) but none of them seem to work with Rails 3.
I've also tried just storing the data in an array until the form is complete, but that was causing my controller to get huge and messy.
Saving models into the session is working unless you want to save a File into the session. The wizard plugins are using the session to store models between the steps. They do not produce errors on valid models in my case only on invalids.
So clearing out the attached file sounded a good idea, but in my case clearing out the paperclip attachment with Attachment#clear was not enough because it still wanted to save some File.
I've found out that the problem was with the #queued_for_write attribute in Attachment which still contained the data.
So the following two lines solved my problem:
unless #model.valid?
#model.image.clear
#model.image.queued_for_write.clear
end
This was a paperclip bug and was corrected in this commit.