Because this took way too much time to figure out:
s3=RightAws::S3Interface.new(S3SwfUpload::S3Config.access_key_id, S3SwfUpload::S3Config.secret_access_key)
old_name = "tmp/#{self.video_file_name}"
new_name = original_video_file_path
bucket = S3SwfUpload::S3Config.bucket
(1..5).each do |try|
begin
acl_prop = s3.get_acl(bucket, old_name)
s3.rename(bucket, old_name, new_name)
s3.put_acl(bucket, new_name, acl_prop[:object])
break
rescue Exception => e
self.video_log += "Problem renaming file, trying again... #{e}\n"
sleep 1
end
end
I installed Exception Notifier on one of our Apps running Rails 2.3.3 and kept running into this error:
Net::SMTPFatalError (555 5.5.2 Syntax error..
A little bit of insight provided this heads up:
But as of Rails 2.3.3, the from email address will get the angle brackets added, so it can only contain the address.
Rails 2.3.4 is/was supposed to fix that, and includes tests so it will be ensured in future versions.
A quick look at the Exception Notifier README and I tried this:
ExceptionNotifier.sender_address = %("app.error@myapp.com)
Success!
The Session
class UserSession < Authlogic::Session::Base
validate :check_if_verified
private
def check_if_verified
errors.add(:base, "You have not yet verified your account") unless attempted_record && attempted_record.verified
end
end
The Migration
class AddVerifiedToUser < ActiveRecord::Migration
def self.up
add_column :users, :verified, :boolean, :default => false
end
def self.down
remove_column :users, :verified
end
end
The User Controller
class UsersController < ApplicationController
...
def create
@user = User.new(params[:user])
if @user.save
flash[:notice] = "Thanks for signing up, we've delivered an email to you with instructions on how to complete your registration!"
@user.deliver_verification_instructions!
redirect_to root_url
else
render :action => :new
end
end
end
The Verification Controller
class UserVerificationsController < ApplicationController
before_filter :load_user_using_perishable_token
def show
if @user
@user.verify!
flash[:notice] = "Thank you for verifying your account. You may now login."
end
redirect_to root_url
end
private
def load_user_using_perishable_token
@user = User.find_using_perishable_token(params[:id])
flash[:notice] = "Unable to find your account." unless @user
end
end
The User Model
class User < ActiveRecord::Base
acts_as_authentic
def deliver_password_reset_instructions!
reset_perishable_token!
Notifier.deliver_password_reset_instructions(self)
end
def verify!
self.verified = true
self.save
end
The Mailer
class Notifier < ApplicationMailer
default_url_options[:host] = "www.myurl.org"
def verification_instructions(user)
subject "Email Verification"
from "myurl"
recipients user.email
sent_on Time.now
body :verification_url => user_verification_url(user.perishable_token)
end
end
The Mailer View
Thank you for signing up for this site. Please click the following link to verify your email address:
<%= @verification_url %>
If the above URL does not work, try copying and pasting it into your browser. If you continue to have problems, please feel free to contact us.
Go here:
/Library/Ruby/Gems/1.8/gems/rails-X.X.X/lib/rails_generator/generators/components/
I was getting this error a lot:
VirtualHost *:80 — mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results
The fix:
I had to remove the default site:
cd /etc/apache2/sites-enabled/
sudo rm 000-default
The file is still available here:
/etc/apache2/sites-available/
But is not conflicting with the config files that deprec sets up.
I over complicated things in my previous solution, and found a better solution while trying to get the WYSIWYG editor to work inside an AJAX form using rails’ remote_form_for.
Using the YUI editor example, set handleSubmit to false and add this right after the MyEditor.render();
// Nate's better Handle Submit
function myHandleFormSubmit(e){
if(state == 'off') {
myEditor.cleanHTML();
};
};
Event.on(myEditor.get('element').form, 'submit', myHandleFormSubmit, myEditor, true);
When doing this and using a AJAX form, try this:
// Nate's better Handle Submit (AJAX version)
function myHandleFormSubmit(e){
if(state == 'off') {
myEditor.cleanHTML();
};
Connect.setForm(e.target);
Connect.asyncRequest('POST', e.target.action, callback, '_method=put');
Event.stopEvent(e);
};
var handleSuccess = function(o){ eval(o.responseText); };
var callback = { success:handleSuccess };
Event.on(myEditor.get('element').form, 'submit', myHandleFormSubmit, myEditor, true);
Hope this helps
Our CityGates app uses the YUI WYSIWYG Rich Text Editor to for all large text areas. Unfortunately, it does not have code / source editing support out of the box. To implement it, you must use some custom code to toggle the textarea / WYSIWYG visibility.
The example from YUI does not use handleSubmit. This means that when a user submits the form from the WYSIWYG editor the textarea does not get updated with the modified information from the iframe when the form is submitted. The user must toggle to the code view to trigger the update to the textarea. Result: a broken WYSIWYG editor.
See example.
The obvious solution: set handleSubmit to “true”. But this causes the converse bad behavior to kick in: When submitting from the code view, the textarea is updated with outdated information from the iframe before the form is submitted. The user must toggle to the WYSIWYG view to update the WYSIWYG. Result: a broken code editor.
See example.
This is what we had setup, and our users were starting to notice.
So a couple of weeks ago I spent some time trying to figure out what was going on, and figured out a crude way to toggle between the handleSubmit behaviors when the user toggles between the views. It isn’t very pretty, but it works.
See solution.
I’m looking forward to when this gets integrated into the final RTE.
Side Note on Our Choice of Editor
We chose to use the YUI RTE because of it’s ability to integrate into any backend system and support image upload and inserting. We love using TinyMCE and their slick uploader on PHP projects, but CityGates is Ruby on Rails.
Updated April 23, 2009
jQuery Cycle plugin is fantastic. However, there is a little bit of inconsistantcy when using it as a left/right slideshow. You click the next arrow, it goes right. You click the previous arrow, it goes left right. The following code allows you to have different effects based on previous/ next button clicks.
Demo
jQuery(document).ready(function(){
$('#blink_headlines').cycle({
fx: 'scrollBothWays',
next: '#cycle_next_blue',
prev: '#cycle_prev_blue',
speed: 1000,
timeout: 0,
pause: 1,
easeIn: 'easeOutBack',
easeOut: 'easeOutBack'
});
});
$.fn.cycle.transitions.scrollBothWays = function($cont, $slides, opts) {
$cont.css('overflow','hidden');
opts.before.push($.fn.cycle.commonReset);
// custom transition fn (trying to get it to scroll forward and backward)
opts.fxFn = function(curr, next, opts, cb, fwd) {
var w = $cont.width();
opts.cssFirst = { left: 0 };
opts.animIn = { left: 0 };
if(fwd){
opts.cssBefore= { left: w, top: 0 };
opts.animOut = { left: 0-w };
}else{
opts.cssBefore= { left: -w, top: 0 };
opts.animOut = { left: w };
};
var $l = $(curr), $n = $(next);
var speedIn = opts.speedIn, speedOut = opts.speedOut, easeIn = opts.easeIn, easeOut = opts.easeOut, animOut = opts.animOut, animIn = opts.animIn;
$n.css(opts.cssBefore);
var fn = function() {$n.show();$n.animate(animIn, speedIn, easeIn, cb);};
$l.animate(animOut, speedOut, easeOut, function() {
if (opts.cssAfter) $l.css(opts.cssAfter);
if (!opts.sync) fn();
});
if (opts.sync) fn();
};
};