Posts Tagged ‘rails’

|

How to ban bad ips in a rails app

The same is applicable for a Merb app, but there might be a better way to do it. Just put the following your application controller.

Remove quoted text from reply emails in rails

the code

and with rough context:

Thanks malkomalko

Setup Paperclip plugin with Amazon S3 to upload videos in rails

This is taken from Clayton Lengel-Zigich. Thanks.

Create a video model.rb

Configure the config/s3.yml file

Configure and install right_aws gem

Then run: sudo rake gems:install & sudo rake gems:unpack

Create a videos controller with the prospective views for the uploading

Configure flash player to display video

1. Download JW FLV MEDIA PLAYER (mediaplayer.zip download link)
2. Copy and paste the player.swf file at public/flash/player.swf
3. Copy and paste the swfobject.js at public/javascript/swfobject.js
4. Configure your application.html.erb file to call swfobject.js in the head

That’s it, you should now be able to upload flv video files and view them in a flash player by going to http://localhost:3000/videos. For instructions on converting quicktimes videos to flash videos on file upload take a look at Jim Neath’s tutorial on converting videos with rails.

Development vs Production mode

It’s a good idea to create a bucket for development and a bucket for production. If you decide to, you can do the following.
Note:this assumes you started your app with bort, and already have a settings.yml that gets loaded by the load_config.rb file using APP_CONFIG = YAML.load_file(”#{RAILS_ROOT}/config/settings.yml”)[RAILS_ENV].symbolize_keys)

In config/settings.yml

In video.rb

Using Gmail with IMAP to Receive Email in Rails (cron job version)

This pretty much comes about because of RailsTips and Peepcode. Thank you guys.

Goal

You want your user to be able to send an email and have that email get posted as a comment to the rails app.

Requirements

1. Your rails app should already have the ability to send out emails
2. Your Rails app must already be capified via Capistrano or similar with some type of deployment recipe
3. You need an additional gmail or google apps account with imap enabled
4. You need the ability to run cron jobs on your server

Configuration

First, setup the cron task and make it easy to run with cap deploy:start and cap deploy:stop

Create file lib/tasks/chores.rake

Create file config/cron.erb

Add the following near the end of your deploy.rb file

Second, setup the login information for the gmail mail account we will use to receive emails through.

Create file config/mail.yml and configure for imap

Install lockfile and tmail cause your gonna need them:
sudo gem install lockfile
sudo gem install tmail

Edit environment.rb

Retrieve the email and save to the database

Edit lib/tasks/chores.rake and put the following code inside the each_minute task. (credit for this goes to John of RailsTips.org though I added a quick fix to handle multipart emails)

Deployment

Deploy your app as usual with cap deploy

Next, run cap cron:start to start up the cron task. This will run every minute.

Send an email to the account you specified in mail.rb and after one minute you should see the email saved as a comment on the app.

Site wide announcements in rails

The go to from railscasts but a little out of date since Rails 2.1 implemented timezones

Fixed to work with SQLite and Rails 2.1

Using jquery

ajax in place editing with rails 2.1 and jquery

Picture 1.png

Install jrails and jrails_in_place_editing

script/plugin install git://github.com/aaronchi/jrails.git
script/plugin install git://github.com/rakuto/jrails_in_place_editing.git

Setup jrails in application.html.erb

1
2
3
<head>
	<%= javascript_include_tag :defaults %>
</head>

Restart your server

Setup jrails_in_place_editing in the..

1. ..Controller

1
2
3
4
class ProjectsController < ApplicationController
  in_place_edit_for :project, :acreage
  ...
end

2. ..View

1
  <%= in_place_editor_field :project, :acreage %>

That’s it. For more on customization and additional options check out the jrails_in_place_editing readme at:

|