ActionMailer sending emails with empty body - ruby-on-rails-3

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.

Related

Attach document to a contact form in rails 3.2

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

How do I report bugs to the rails team?

I found a weird bug in Rails 3.0.? that I want to report to the Rails team, but I have no idea how to do it.
Does anyone here know how to do this? Where is the open source project hosted? Do they have have ticket system?
Actually, I am going to share the issue I found, maybe it really isn't a bug. I am using Rails 3.0.7 and Ruby 1.8.7.
I created some static pages and I have two pages that are named very similar one named "holiday" and the other named "holidays". First, I created the singular "holiday" page and everything worked as it should. Then I created the plural version of it and when I tried to test it didn't work, I kept getting redirected to the not found or 404. Just to be clear, yes I restarted the server but that didn't fix the problem. The only way this weird issue went away in when I cleared the browser cache.
Here are the code snippets.
In the routes I added this:
match '/holiday' => 'pages#holiday' , :as => 'holiday'
match '/holidays' => 'pages#holidays' , :as => 'holidays'
in the controller I just added empty actions
def holiday(); end
def holidays(); end
somewhere in the views folder I have the corresponding pages "holiday.html.erb" and "holidays.html.erb".
When I visit the first page (/holiday) it works. The page gets served.
When I visit the second page (/hoidays) it doesn't work. I get redirected to the not found / 404 page.
Has anyone encountered this weird issue in Rails 3?
Here's the bugs/issues system:
https://github.com/rails/rails/issues
You can search for the bug before submitting it. Maybe someone already reported it.

how to use self.response_body in a view

I want to stream a large amount of text from a controller to a view in real time and was pointed to using the following code as an example of how to handle the streaming
def home
self.response_body = proc {|resp, out|
10.times do |x|
out.write "count = #{x}"
sleep 1
end
}
Now this code works in so much the content streams to a browser with 1 line appearing every second, however it doesn’t use the home.html.erb view I created instead it only renders a blank page with the streaming data on it
I’ve tried to embed it using various bits of erb code but cant get it to work and I’ve had a hunt around the web and cant see any clue as how to do this
Can anyone help?
I'm using Rails 3.0.7 and ruby 1.9.2, in dev I'm using unicorn as the rails server which handles the streaming
Cheers
Mike
If you set the response_body in the controller it will not render the view. So I'm afraid you have to pick one or the other. In fact, I've received an exception when I tried to send a response to the client via two different methods. In my case it was send_data and self.response_body = ...

Rails3 UJS response not evaluated

It gives me the creeps,i'm done, i need some help here, i reverted multiple times back but i can't find the error.
Simple controller (customers),a simple form for adding a customer via :remote => true and the controller does respond_to do |format| { format.js } . Works fine, renders my create.js.rjs template.
I work for a few hours without making any javascript changes or changes to my controllers or authorization etc.. and when i try it again it's not working anymore.
What i mean with not working: Controller gets called, record saved, all partials rendered. But no javascript evaluated, not even a simple alert(1) at the beginning of the file.
I tried with different prototype.js versions and different rails.js versions, but nothing helped. I hope someone has a clue about this or already experienced this.
It's not that i don't want to post code. But it won't help. Its basic code that works and, after some changes where i don't know what i really changed (some locales here, some css there, html templates from a completely different controller a bit..)..
Currently developing with: ruby 1.9.2, rails 3.0.3, prototype 1.7 RC3, rails.js from github.
SOLVED
How stupid, I missed the part where the template naming changed. My application templace was named "application.rhtml". It worked until now. As it stopped to work, I changed it to "application.html.erb" and now it's working.

Rails and mongoid: What is going on with RC7 and embedded documents?

Until now I was using rc6 and I decided to upgrade, but it's totally
breaking my app ? Maybe I am doing something wrong, but I believe I
followed the documentation.
I have a model Content that embeds_many Localized_Content.
Once I have a content created and wanted to added a localized content
I would do the following:
#content = Content.find('xxx')
#new_content = #content.localized_contants.build()
#new_content.save
This is working perfectly fine under rc6 and updates correctly all the
timestamps in localized_contant (using include Mongoid::Timestamps)
But doing the same thing in rc7 break with the following error:
"Access to the collection for LocalizedContent is not allowed since it
is an embedded document, please access a collection from the root
document."
Ok, maybe I need to save directly from the parent content then ok.
Doing a
#content.save
works but will not trigger all the timestamping
and this breaks the logic of my apps... what should I do ?
#content.save is the way to go. You should refactor your code to call save() on the parent object instead of the embedded document.