RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

In case anyone gets stumped by task.save(false), as of rails 3 use task.save(validate: false).

See 3.0 release notes: save(false) is deprecated, in favor of save(:validate => false) and the API.

The related error you may see is

NoMethodError (undefined method `[]' for false:FalseClass)

Avatar

Can I integrate ActiveAdmin in views/layout/application.html.erb

<html><head>
<title> .... </title>
</head><body>
...
<div class="active_admin">
active_admin yield
</div>
...
</body>
</html>

Avatar

nice piece of app. I finally get it right. Thanks, I've been looking for this for a month already.

Avatar

good job!

i have one question.. method 'data:', is only in rails 3.1 ?

Avatar

Is this railscast still relevant?

I read that I need to use find(:all) now for 3.1

Avatar

There's nothing wrong with that approach either. I think it depends on the specific use case.

I have both strategies in one of my apps. Visitor searches on the public site are not stored, but admin searches in the marketing module are because they provide the criteria for targeting a segment of a marketing list which is then used by a backend job to send emails. Since the list changes as subscribers come and go, having the list based on search criteria is essential.

So this type of advanced search definitely has it's use case. Thanks for the revision Ryan.

Avatar

Using it for my puppy project, flows smoothly now after some tinkering :-)

https://github.com/RobertBrewitz/articulated

Avatar

I have a weird issue...
calendar is generating for all articles in my blog e.g. I have 5 articles so each article has own calendar on main page.

<%= calendar_for @articles do |calendar| %>
<%= calendar.head('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')%>
<% calendar.day(:day_method => :published_at) do |date, articles| %>
<%= date.day %>
<% end %>

<% end %>

I'm using rails 3.1

How to fix it?

Avatar

Hi, receiving the following error when clicking my "Log In" link:

Routing Error

undefined method `username_attribute_name=' for #Sorcery::Model::Config:0x41a2730

Avatar

What's wrong with not having a database backend at all, configuring the attribute accessors manually and have the create action of the controller show the search result (after possible validations)? I guess re-using the search has its niceities, but how often will it actually get used in an average app?

Avatar

I got testing with rspec working here, note that I am using mongo(oid) and not ActiveRecord (same principle though):

https://github.com/RobertBrewitz/EngineRspecMongoid

NOTE: I think I found some bug in the rails plugin new generator with camel casing. More here: https://github.com/rails/rails/issues/3684

Avatar

Just a small comment on the pruning of old searches. I think it's generally bad behaviour to remove old searches. People might link to it, expect it to remain, and boom, suddenly it's gone.

It's probably better to check if a specific search already exists before creation and redirect to it if need be.

Avatar

Hi Ryan,
you should use »rails generate sorcery:install« instead of »sorcery:bootstrap«.
Have fun!

Avatar

Thank you Daniel.
I will just look at ElasticSearch with Tire gem. I assume that i would integrate ElasticSearch in my project.

Avatar

farukca: I just try to develop a file flowing. We have some papers comming from other companies. These files includes some unordered information. So somebody make ocr or writedown this unordered fields. And searching on it.

Avatar

Hey Ryan! Thanks a lot!
I have a little problem here.
Do i have to make any changes in my controller? The view is perfect, but when I click "send", nothing is updated. Thanks!

Avatar

I had used ElasticSearch with mebla gem, it was working so good and easy to configure on production. But I will try solr this time, because it's mongoid configuration is so simple.
Murat hocam, sen nerede kullanacaksın fulltext aramayı ?

Avatar

Murat: Sunspot is a ruby wrapper for Solr. Another search engine to check out is ElasticSearch (and the Tire gem for it). It has some nice features like distributed indices for high availability and it's a lot easier than to set up than solr.

Avatar

What could also speed up your process is to tell your specs to halt after first failure:

RSpec.configure do |config|
  config.fail_fast = true
  ..
end
Avatar

Thank you Ryan for this advanced search screencast.

Is there any suggestion for us about fulltext search engines? In Ryan`s screencasts, before,
he show us Sphinx and Sunspot, what about Solr?

Regards.

Avatar

Thanks VonD,

I finally had a chance to get back to this and discovered that tonight. After getting it working I came back here to let David know how I solved it. You are correct, the timeout is very low and at least for me running nginx/passenger/rails in dev mode is just too slow to respond. I changed the JS/CoffeeScript to:

ruby
jQuery ->
   $('a').pjax('[data-pjax-container]', {timeout: 2000})

Now it's working find :)

Avatar

i am getting this error when try to run sudo service unicorn restart

/usr/bin/env ruby-local-exec no such file or direcotry

i am using rbenv and have done 'rbenv local 1.9.2-p290' in my project

what can be the issue?

Avatar

I'm trying to use rack-pjax on the top div container and I can see the performance difference even the pushState reload whole body (header still loaded)

Avatar

ryan,

thanks for the railcast! as a noob, this is just what i have been looking for.

question.... the basic spree store that i got up and running seems to be missing a number of elements like the links for the shopping cart, search bar, etc.. and when you click on a product it goes to a blank page. this is different than what you illustrate here. i read that the basic spree install is basic... it just seems that the one i have set up is much more basic than the one illustrated. i would appreciate any advice or direction as to what i might be missing. i am using, spree 0.70.1, ruby-1.9.2-p290 and rails 3.1.1.

thanks,

bob

Avatar

I don't know what happened, but restarting nginx and unicorn multiple seems to have solved the problem and it hasn't reappeared yet. I still wonder what caused it though.

Avatar

I followed by letter the screencast tuto but got the below errors:

serge@serge-laptop:~/Development/Ruby/test_projects/blog$ guard
Please install libnotify gem for Linux notification support and add it to your Gemfile
Guard is now watching at '/home/serge/Development/Ruby/test_projects/blog'
Starting Spork for RSpec & Cucumber 
Using RSpec
Using Cucumber
Preloading Rails environment
Preloading Rails environment
Loading Spork.prefork block...
Loading Spork.prefork block...
ERROR: Could not start Spork server for RSpec & Cucumber. Make sure you can use it manually first.
Guard::RSpec is running, with RSpec 2!
Running all specs
No DRb server is running. Running in local process instead ...
No examples found.


Finished in 0.71765 seconds
0 examples, 0 failures
Spork is ready and listening on 8989!
Spork is ready and listening on 8990!

Any idea about the error? Thanks

Avatar

Has anyone else noticed that http://guides.rubyonrails.org/initialization.html isn't in the guides index? Would've been helpful to have that link a year ago!

Avatar

It works but somehow mine seems slower than Ryan's. Am I missing something or did he do some creative video editing? ;)

Avatar

Any ideas as to why I receive the following error message when I run rake db:bootstrap --trace per the instructions in the readme for this episode?

This task will destroy any data in the database. Are you sure you want to
continue? [y/n] y
rake aborted!
undefined method set_preference' for nil:NilClass
/home/family/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.1/lib/active_support/whiny_nil.rb:48:in
method_missing'
/home/family/.rvm/gems/ruby-1.9.2-p290/gems/spree_core-0.70.1/lib/spree/preference_access.rb:18:in block in set'
/home/family/.rvm/gems/ruby-1.9.2-p290/gems/spree_core-0.70.1/lib/spree/preference_access.rb:17:in
each'
/home/family/.rvm/gems/ruby-1.9.2-p290/gems/spree_core-0.70.1/lib/spree/preference_access.rb:17:in set'
/home/family/Desktop/APPS/Episodes/EPISODES/ryanb-railscasts-episodes-8f0f990/episode-298/store-after/config/initializers/spree_config.rb:1:in
'

Avatar

Forget my comment above. It's working. Not sure what i was doing wrong. I updated the project to use bundler and it works fine. Thanks.

Avatar

Hey, I'm having trouble with redirecting. I have the same nginx.conf as in the tutorial, and when I do redirect_to posts_path in my controller, I get redirected to http://unicorn/posts, instead of http://example.com/posts. What could've I missed?

Even if I do just redirect_to '/', I get redirected to http://unicorn/.

Avatar

Wow... eye opening... I, as well, would love another one of these.

Avatar

Hi Ryan,

I'm trying to get your example to work, but having no luck with content_for. There is never any content added in the layout where you have

ruby
<%= yield :head %>

I pulled the latest code off github and having the same issue.

Avatar

How about seeing to integrating into existing app. Thanks for screencast! Great job!

Avatar

I used this script to install Image Magick on previous applications, seemed to work good: https://github.com/maddox/magick-installer

Avatar

Ok guys I figured out my above problem, had to enable IPN for my paypal account.

Thanks
Rohan

Avatar

Thank you Ryan,

In fact, with Active Reload the server is really fast in production mode.

Thanks

Avatar

I haven´t got the cropper module to work with Ryans code, but this works for me

ruby
module Paperclip
  class Cropper < Thumbnail
    def transformation_command
      if crop_command
        crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ') # super returns an array like this: ["-resize", "100x", "-crop", "100x100+0+0", "+repage"]
      else
        super
      end
    end

    def crop_command
      target = @attachment.instance
      if target.cropping?
        ["-crop", "#{target.crop_w}x#{target.crop_h}+#{target.crop_x}+#{target.crop_y}"]
      end
    end
  end
end
Avatar

What about doing stubs and mock objects for request specs? I know it's possible in FactoryGirl but I never quite got the hang of it

Avatar

Is IPN working for anyone? I am not receiving IPN on payment made or for the recurrence.

My sandbox application is available on externally accessible domain.

Any help on this?

Thanks
Rohan

Avatar

Sorttable is ridiculously easy to use, unobtrusive, and doesn't require all those http requests.

Thanks for the suggestion!

Avatar

Hello Ryan,

First of all thanks for the great work about nested objects. When i tried your example in my application IE gave me an error that object does not support method for jQuery hide() method. I did everything to figured out problem but none of them worked.

-copied jquery files to /assets/javascripts did not work !
-copied content of jquery.js file to application.js did not work!
-changed application.html.erb file like this
<%= javascript_include_tag "jquery","application", :cache=>true %> did not work.

My rails version 3.1.0

thanks..

Avatar

Great episode Ryan!

It would be AWESOME if you could go into more depth in stripe, even if it is with the pro subscription. It would be very very useful.

Thanks!

Avatar
  • 1 for this episode, but a future episode going into more depth in stripe would be + 100 !
Avatar

@Ryan: yet again you've done a great tutorial job. Thanks for covering this episode with Spree. In version 0.80, we plan to have the namespace for the sake integration with other such as RefineryCMS. I hope you will create another tutorial on Spree integration.

Avatar

The best way i've found to do this is to just add a route in your routes file like:

ruby
match '/editor(/*requested_uri)' => 'mercury_auth#edit', :as => :mercury_editor

Then create a new controller that inherits from MercuryController, like:

ruby
class MercuryAuthController < MercuryController
  include SessionsHelper

  before_filter :authenticate_with_admin, :only => [:edit]
  def edit
    render :text => '', :layout => 'mercury'
  end
end

Then, you can get all the functionality of Mercury, but limit access on requests like that. That might be a bit closer to what you were looking for.

Oh, and be sure to add that route before the mercury routes in your routes.rb file

Avatar

Maybe the request is just meeting a timeout, in which case it falls back to a normal request. You can configure the timeout delay, which is by default 650ms.

Avatar

Tried this with locations for a new event. It was working fine then I deleted a location and it keeps trying to download a json file instead of displaying the index. Any ideas?

Log:
Started GET "/locations" for 192.168.. at 2011-11-15 14:20:10 -0500
Processing by LocationsController#index as HTML
Location Load (3.2ms) SELECT "locations".* FROM "locations"
Location Load (2.0ms) SELECT "locations".* FROM "locations" WHERE (name like '%%') ORDER BY name
Completed 200 OK in 89ms (Views: 7.8ms | ActiveRecord: 8.4ms)

Avatar

In addition to being a great video overall, it also just introduced me to tap. Thanks Ryan :)