WordPress “No Such User Here” Error With Formidable Forms

I set up a domain on Google Apps with some email addresses, and wanted to send contact information from a WordPress form that was using Formidable. However, the emails weren’t being sent correctly from the form. When I sent a message from my Gmail account, the message went through correctly (I set up another email on the same domain for testing purposes).

Inspecting the mail error logs (for me on the shared hosting, was at ~/mail/new/*), I got things similar to the following:

Return-path: <>
Envelope-to: username@zzzzzzz.com
Delivery-date: Thu, 15 Dec 2011 15:19:24 -0700
Received: from mailnull by zzzzzzzz.com with local (Exim 4.69)
id 1RbJe8
for username@zzzzzzzzzz.com; Thu, 15 Dec 2011 15:19:24 -0700
X-Failed-Recipients: admin@mywebsite.com
Auto-Submitted: auto-replied
From: Mail Delivery System 
To: username@zzzzzzz.com
Subject: Mail delivery failed: returning message to sender
Message-Id: 
Date: Thu, 15 Dec 2011 15:19:24 -0700

This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

  admin@mywebsite.com
    No Such User Here

I searched around a bit, and it seems like it was Google Apps rejecting the email that I was sending from the shared hosting environment. To solve this, I wanted to authenticate with Gmail and use that as the SMTP server.

I followed the instructions here and it seemed to work out well. I was able to send emails effectively to the Google Mail account after putting in my testing account’s information as the username/password. This worked with WordPress 3.1.

Hope this helps!

Leave a comment

WordPress Posts Not Saving

I was having a problem where WordPress post drafts on my main blog were not saving. I would press the schedule/publish/update button when I was in the HTML view mode (the default mode that I edit in), and the text would change from a monospaced font to a non-monospaced font. Nothing would happen otherwise. I would press the button again, and all of the text would completely disappear, and my work would be lost. Nothing would save to the database. I had to go into the quick edit mode on the all posts page to actually edit anything. Clearly this was unacceptable.

Here are the steps I took to fix it:

  • Ensure I was running the latest version of WordPress (I was)
  • Ensure that all of the plugins that I had were completely up to date
  • Disable any new or flaky plugins, or those dealing with editing that might have caused the problem
  • Somehow proofreading got turned on, and this seemed to cause problems. See here to turn off WordPress proofreading.

After doing that, things seemed to work much better on the saving front.

Leave a comment

Titanium and Database Download From Server

My goal: to have a mobile app that downloads its initial database from the server instead of pulling the data down through the normal API one at a time. This was for speed reasons, and there are probably other implementations and methods to try. Basically, if the app has never synced, pull down the database.

A bunch of posts on the subject (not exactly what I needed, but helpful):
Using a local database with Titanium
Update database and table content
DB install from remote sqlite file
The official database documentation
Some helpful SQLite documentation for generating the dump from your database
A nice way to programmatically modify the table that you dumped with some examples

The project happened to be using joli.js for persistence. My code eventually looked something like this:

function checkForBlankDb(callback) {
  if (models.somemodel.count() === 0) { // never pulled from server
    Ti.API.debug("Going to try to download the database");
    activityIndicator.message = 'Downloading database...';
    activityIndicator.show();
    var xhr = Ti.Network.createHTTPClient();
 
    xhr.onload = function() {
      var f = Ti.Filesystem.getFile('file:///data/data/myprojectpackage/databases/mydb');
      Ti.API.debug("f.nativePath: " + f.nativePath);
 
      // key if you have opened the db, I needed to extend Joli to do this
      joli.connection.close();
 
      // remove the file, not entirely sure this is necessary
      if (f.exists()) {
        Ti.API.debug("deleting the file at nativepath");
        f.deleteFile();
      }
 
      Ti.API.debug("going to write data");
      f.write(this.responseData); // actually write the data we got
      Ti.API.debug("wrote data");
 
      Ti.API.debug("reconnecting to database");
      joli.connection = new joli.Connection('mydb');
 
      Ti.API.debug("should have successfully synced.");
      callback();
    };
 
    xhr.onerror = function() {
      alert("Could not connect to server to download.");
      // TODO: better error handling
    }
 
    xhr.open('GET', serverpath + '/downloads/database');
    authenticate(xhr);
    xhr.send();
  } else {
    callback();
  }
}

The long and short of it is that if you do something like opening a database mydb, it stores it at the file path listed up in the code sample (file:///blah). This is only for Android, the path for iOS is different. There are ways to generate that path more dynamically, but this works for now. If you want to see exactly what you are creating, use `adb -e shell` to check out the file system. The callback stuff makes the asynchronous call basically synchronous, because I wanted to do some things immediately after that required the database being loaded. Most of the time, the initial check would pass, and we would not download the database again (just look for diffs.) Hope this helps!

Leave a comment

form was removed from Rails and is now available as a plugin.

I got this strange error when in my Rails application:

DEPRECATION WARNING: form was removed from Rails and is now available as a plugin. Please install it with `rails plugin install git://github.com/rails/dynamic_form.git`.

What ended up happening was that I forgot to pass in a local ‘form’ to a partial that was expecting it to be passed in. Rails then didn’t know how to handle the form that I was trying to set, and so it fell back to some default behavior of saying that the way I was using form was deprecated.

1 Comment

What are Some Great Posts on Debugging Tough Problems?

Even if you are not running the same technology as someone else, you can gain insight into how they solve hairy problems by reading through their summaries of strange fixes.

Today there was a great post on debugging CSRF problems in Rails. I thought it was interesting and had run into something similar but not nearly as convoluted. It was useful to see the steps that the post author took to figure out what was the root cause of the problem, tracking back to what the change in the Rails code base was that caused him to have invalid assumptions.

What are some great debugging posts that you have read in the past? (Maybe even something on Reddit or Hacker News) Share them in the comments!

Leave a comment

Rails Raw SQL Insert — Time Wrong

If the time is incorrect on something that you insert directly into the database when using Rails (off by several hours), try ensuring that you are using the correct modifier to get it into the right time zone. For example, instead of doing DateTime.now, try DateTime.now.utc if you are using UTC as your default timezone.

1 Comment

Converting ERB to Slim

I looked around and there was seemingly no easy way to convert Rails apps to use Slim instead of ERB. There was a gem out there, but it didn’t seem to work for me.

The general process I used was to first convert ERB to Haml using Haml’s haml2html. Next, convert Haml to Slim using haml2slim.

Convert ERB to Haml

Ensure you have Haml installed, preferably using your Gemfile if using Bundler. You can probably remove Haml when you are done with this process.

I got much inspiration from this article on the conversion process.

# to test what you will convert
find . -name '*html.erb' | \
xargs ruby -e 'ARGV.each { |i| puts "html2haml -r #{i} #{i.sub(/erb$/,"haml")}"}'
# to convert
find . -name '*html.erb' | \
xargs ruby -e 'ARGV.each { |i| puts "html2haml -r #{i} #{i.sub(/erb$/,"haml")}"}' | bash

Somewhere in this process the whitespace gets mostly stripped out. This is unfortunate, but should take less time overall to fix than converting over by hand.

Then, assuming you are using version control (not sure how much longer I will believe that this is not universal), remove the .erb files.

rm -rf "**/*.html.erb" # works in zsh at least...

This is important because Rails will look at your *.erb files first, so if you don’t delete them then the results of running html2haml won’t be seen.

Fix anything that is broken. In my case it was some illegal nesting and bad indentation problems in a couple of partials, as well as some other things that needed to be changed.

Look through the app in the browser if your tests don’t cover all of the views and for a sanity check. You may have to restart your server if you installed Haml.

Convert Haml to Slim

Ensure you have Slim installed, preferably using your Gemfile if using Bundler. Run `gem install haml2slim` (we don’t need this in the Gemfile since it’s for one-time use not in the application.)

Slim template files have the ending extension .slim, like their counterparts ERB (.erb) and Haml (.haml).

Again, we use a converter.

find . -name '*html.haml' | xargs ruby -e 'ARGV.each { |i| puts "haml2slim #{i} #{i.sub(/haml$/,"slim")}"}' | bash

Again, we delete the extra files (**/*.html.haml this time).

Again, we fix anything that is broken.

Now hopefully your app should be fully converted to use Slim! Suddenly a puppy appears and the sun comes out from behind the clouds.

Leave a comment

Bundler see what updates are available

The command to see what gems have more recent versions and can be updated is `bundle outdated`. This will show you all gems that could be upgraded, but unlike `bundle update`, will not actually update your gems (changing Gemfile.lock and installing new gems.)

It will output something like:

$ bundle outdated
Updating git://github.com/panozzaj/andand.git
Fetching gem metadata from http://rubygems.org/.......
Fetching gem metadata from http://rubygems.org/..

Outdated gems included in the bundle:
  * ZenTest (4.6.2 > 4.5.0)
  * activesupport (3.1.1 > 3.0.9)
  * builder (3.0.0 > 2.1.2)
  * i18n (0.6.0 > 0.5.0)
  * activemodel (3.1.1 > 3.0.9)
  * erubis (2.7.0 > 2.6.6)
  * rack (1.3.4 > 1.2.4)
  * rack-mount (0.8.3 > 0.6.14)
  * rack-test (0.6.1 > 0.5.7)
  * actionpack (3.1.1 > 3.0.9)
  * mail (2.3.0 > 2.2.19)
  * actionmailer (3.1.1 > 3.0.9)
  * arel (2.2.1 > 2.0.10)
  * activerecord (3.1.1 > 3.0.9)
  * activeresource (3.1.1 > 3.0.9)
  * devise (1.4.2 2a5ad46 > 1.4.2 e76ba05)
  * railties (3.1.1 > 3.0.9)
  * rails (3.1.1 > 3.0.9)
  * sequel (3.28.0 > 3.20.0)
  * sinatra (1.3.1 > 1.0)

To break it down, “sinatra (1.3.1 > 1.0)” means that I have version 1.0 and version 1.3.1 is available.

Potential stumbling blocks

Getting a ‘Could not find task “outdated”.’ error message when trying to run `bundle outdated`?

At the time of this writing you need to have the right version of Bundler installed with `gem install bundler --pre`. This installs Bundler version 1.1.rc, which should also be much faster than earlier versions of Bundler. I would expect this portion of this post to be outdated in the near future.

Leave a comment

Slim “Failure/Error: render ActionView::Template::Error: Unexpected end of file”

I was getting an error from Slim template saying:

Failure/Error: render
ActionView::Template::Error:
  Unexpected end of file
    my_file.html.slim, Line 15

, where the file had only 15 lines

I searched for the error and found:

# https://github.com/stonean/slim/blob/master/lib/slim/parser.rb
def parse_broken_line
  broken_line = @line.strip
  while broken_line[-1] == ?\\
    next_line || syntax_error!('Unexpected end of file')
    broken_line << "\n" << @line.strip
  end
  broken_line
end

What this means is that I had an extra trailing slash on one of the lines in a Slim escape that indicates that there are multiple lines. Slim was expecting another line, but didn’t see it and instead saw the end of the file. Removing the extra trailing slash fixed the problem.

Leave a comment

How I Patched Devise to Force Login for Twitter and Facebook

Here were some of the things that I had to do to Devise to get things working correctly with Twitter and Facebook. YMMV, as this was six months ago and I had some special requirements potentially.

# /config/initializers/omniauth_patch.rb
# see http://stackoverflow.com/questions/1960957
module OmniAuth
  module Strategies
    # override authorize path to force user to login each time
    class Twitter < OmniAuth::Strategies::OAuth
      def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
        client_options = {
          :site => 'https://api.twitter.com'
        }
 
        client_options[:authorize_path] = '/oauth/authorize'
        super(app, :twitter, consumer_key, consumer_secret, client_options, options)
      end
    end
  end
end
  # in config/environments.rb
 
  config.omniauth :twitter, 'XXXXXXXXXXXXX', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
 
  # Created multiple Facebook apps for testing because you can only have
  # one per domain. One way to lessen these would be to set up staging.myapp.com, etc.
  # since Facebook respects subdomains as being on the same domain. Would still need one for
  # localhost testing though (unless I set up hosts file differently?)
  # This seems simplest for now though.
  id, secret = case ENV['RACK_ENV']
  when 'production'
    ['XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX']
  when 'staging'
    ['XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX']
  else
    ['XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'] # localhost
  end
  config.omniauth :facebook, id, secret, { :display => :touch }

The last line ensures that we use the facebook touch view because I was only targeting mobile devices (iPhone). I’m not sure how we would easily do this at runtime besides further patching. Basically this limits us because we have to use the touch even though we want to use the web version on the web.

When signing out, I want to ensure that I sign out of all of the services that I might be signed into. I do a bit of a hack in the sign out view with:

  Not you? #{link_to 'Sign out', "http://m.facebook.com/logout.php?confirm=1&next=#{destroy_user_session_url}"}

Basically we ask facebook to sign us out first, and then go into the normal sign out.

Leave a comment