RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

This was fixed very recently. It works if you use the newest commit (as of right now):

ruby
gem 'mercury-rails', git: 'https://github.com/jejacks0n/mercury.git', ref: '6d9c99fe20958ed87e4f1a05e9de19825af702ef'
Avatar

I like your approach. Thanks for sharing.

Avatar

Such an amazong epsiode. I was reading on this full text searching for PostgreSQL before, but I didn't understand quite a lot of things, and this really cleared things up. Thank you so much :)

Avatar

May I ask how I can get the cache monitor at the bottom of the screen?

Avatar

You might need to reinstall the pg gem, possibly with pg config path specified http://deveiate.org/code/pg/

Avatar

Is it possible to have condition clause in searching like has clause in thinking sphinx ?

Avatar

Thank you Ryan. I like this nested model forms that starting from scratch. This is awesome.
+1

Avatar

How do i get it to work with simple form?

Avatar

Hwaaaa! Awsome timing. I just started adding Sphinx to my application, and I'm already using Postgres. For my particular needs, Postgres apparently offers more than enough. Thanks again very much Ryan.

Avatar

Very nice cast. That pipeline can get convoluted. Thank you!

Avatar

Does this mean if we switch to postgres from mysql, we no longer need solr or sphinx anymore?

Avatar

I actually feel good about spending the $9 per month for episodes like this! That's a big statement considering how cheap I am.

Avatar

Great screencast, I was using texticle already but this has given me much more flexibility.

Has anybody else ran into an error when creating the unaccent extension? I'm running rails 3.2, I've had no problems elsewhere in this screencast for some reason or other its not liking this migration, I've triple check the syntax

ruby
==  AddUnaccentExtension: migrating ===========================================
-- execute("create extension unaccent")
rake aborted!
An error has occurred, this and all later migrations canceled:

PG::Error: ERROR:  syntax error at or near "extension"
LINE 1: create extension unaccent
               ^
: create extension unaccent

Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Avatar

Found an even better way to do it! It's in the readme for the jquery-datatables-rails gem:

Twitter Bootstrap 2 support
Add the JavaScript to application.js:
//= require dataTables/jquery.dataTables.bootstrap

Remove the initial stylesheets from application.css
Add the stylesheets to application.css:
*= require dataTables/jquery.dataTables.bootstrap

Initialize your datatables like this:
// For fluid containers
$('.datatable').dataTable({
"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap"
});

// For fixed width containers
$('.datatable').dataTable({
"sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap"
});

https://github.com/rweng/jquery-datatables-rails

Avatar

Amazing how much simpler this is, especially since the power shown in the unrevised editions is one of the thing that made me think Ruby was so much better than the alternatives. Thanks, Ryan!

Avatar

Thank you for your feedback. I am guilty of not providing enough documentation.
Since the gem was mostly used on internal projects, like tr8n admin tools and others, i never did my part on documenting it.

Well, i am fixing this now. Here is a document on customizing the table view:

https://github.com/berk/will_filter/wiki/Customizing-Table-View

Avatar

Wow, I moved to pg over a year ago so I could use Heroku. I never even knew it would help me with search. I have some code to update. Thanks!

Avatar

Every time I think I really know what I'm doing in rails you humble me. This is so simple and useful, and I didn't know it. Thanks so much!

Avatar

Works in HTML5, is cut off with Flash.

OSX Lion with Chrome 19.

Avatar

I'm using Cocoon... it seems pretty good so far.

Avatar

thanks Ryan...

@anyone Does anyone have an example carrierwave intregration (file or image upload in in a nested model)

Avatar

This was one of the first casts that got me into Railscasts so I'm glad to see an update.
Just a word of caution to new users of this technique: when you have a hammer everything can look like a nail. Dynamic nested forms like this are extremely powerful and can sometimes grant the user too many chances to input bad data.

If you find yourself needing complex validations to regulate the the data coming in from the form, a solution like this might not be what's in order and you might want to limit the scope of what is possible to do. Ryan's simple example here is spot on.

This dynamic nested form technique has worked wonders for me (Thanks, Ryan!) but I've been bitten by applying it to the wrong use cases-- use discretion when deciding on a UX.

Avatar

I know this is old... But it made my day!

Avatar

There was an earlier episode on MongoDB here.

Avatar

The PostgreSQL notices in the console really annoy me. You can turn them off by adding min_messages: warning in your database.yml file. See example

Avatar

The example I have is something like:

http://omarqureshi.net/articles/2010-12-25-tsearch2-for-rails-applications

I re-use the same function for inserts that i do for updates and just call it differently inside the trigger. The only real bit of duplication is the refresh function - which i have for existing content only.

Avatar

Nice episode, but I would recommend to set Http-only setting for auth-cookies so if site somehow have xss hole attacker cannot steal cookies through javascript.

Avatar

how about MongoDB? what's the Pro/Cons?

would love an episode on mongoDB

Avatar

FYI, I was able to have the same styling on the f.button when omitting 'btw' from :class, since 'btn' is one of the default classes the Twitter Bootstrap-powered version of SimpleForm has (defined in config/initializers/simple_form.rb):

products/_form.html.erb
<%= f.submit nil, :class => 'btn-primary' %>

Can leave out 'btn' from :class because its specified here:

config/initializers/simple_form.rb
# Default class for buttons
config.button_class = 'btn'
Avatar

Thanks for the episode. I followed along and everything worked as expected (I did have to take aharte's advice to move /usr/local/bin above /usr/bin in /etc/paths to get 9.1.3 recognized).

However when I run "rails db" and try any commands against postgres I get a segmentation fault: 11. I installed postgres with the > brew install postgresql used in the railscast. I'm on Lion and > psql --version returns "psql (PostgreSQL) 9.1.3"

Any thoughts on the segmentation fault?
Thanks.

Avatar

andreteves, did you have any luck resolving this issue? I'm getting the same error?

Thanks.

Avatar

Helpful for me. It's nice to have a visual walkthrough so I can see it step by step, especially since I'm new.

Avatar

The veil is lifted.

(But yes, that's probably the right answer)

Avatar

Ubuntu 12.04 with Chromium 18.0.1025.151:
Works fine with HTML5 and cuts with Flash, so no worries :)

Avatar

Heroku's db:pull functionality was formerly based on yaml_db and has since moved to taps. I have had less problems with taps, though, i've used yaml_db to change schema in mass on existing data.

Avatar

Albino has been deprecated in favor of pygments.rb. This code combines both redcarpet 2.1 and pygments.rb

ruby
module ApplicationHelper
  class HTMLwithPygments < Redcarpet::Render::HTML
    def block_code(code, language)
      Pygments.highlight(code, :lexer => language)
    end
  end

  def markdown(text)
    renderer = HTMLwithPygments.new(:hard_wrap => true)
    options = {
      :fenced_code_blocks => true,
      :no_intra_emphasis => true,
      :autolink => true,
      :strikethrough => true,
      :lax_html_blocks => true,
      :superscript => true
    }
    Redcarpet::Markdown.new(renderer, options).render(text)
  end
end
Avatar

This is easy to understand:

  • foo package provides binary executable of foo.

  • foo-dev package contains header(.h) and library(.so) files for compiling related sources.

Since pg gem is a native gem that needs to be compiled against pg library, you need libpq-dev.

Avatar

And I want to point out a PGCon2009 video: PostgreSQL as a secret weapon for high-performance Ruby on Rails applications.

It suggests replace complex ActiveRecord logic with SQL to gain performance boost. The examples such as act_as_tree are impressing. The major disadvantage is that you can no more change db adapter easily.

Avatar

A simple note:

pg gem uses prepare statement in production env by default, which is different from MySQL.

This can be an issue if you are using unicorn. You may got PGError: ERROR: prepared statement "a3" already exists after several requests.

To solve this, make sure each unicorn process uses its own database connection by adding this to unicorn config file:

ruby
after_fork do |server, worker|
  ActiveRecord::Base.establish_connection
end

Hope this helps :)

Avatar

I am using will_filter since a few days and it seems like a really helpful gem. My favorite feature is that you can combine saved filters to new filters. There is not that much documentation on customization but code to look into. A good starting point is the dummy application or parts of tr8n.