RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

If you have problems with url helpers while running zeus, I could be wrong but believe it's because of this here.

I applaud that effort to optimize time, but like spork, I've kicked zeus to the curb. They make the test environment just a little too dissimilar from the production and development environments. I wind up spending a lot of time tracking down bugs in my code... or my tests... only to learn it's neither; it's my testing environment flaking out. So how much time is it really saving? (BIG fan of guard, though.)

YMMV

Avatar

They changed the string array to a PathSet class in Rails 3.2.

To see it as a string array, <%= controller.view_paths.map &:to_path %>

Avatar

is there a way to use this with the acts_as_commentable gem?

Avatar

Hello. I have a problem. This app use sqlite3, but i need postgresql. I edit my Gemfile and database.yml. My app work in rails server, but on heroku doesn't. May be it's needs to edit something other. Write me please, what i needs to edit to use postgersql.

Avatar

Brilliant screencast. I expected some basics but you even went as far as developing jQuery plugins. And you show common pitfalls. Thanks so much.

Avatar

Same problem here. If I run "cap deploy" after a failed "cap rubber:create_staging" deployment I'll get the following error:

** [out :: production.blog.com] rake aborted!
** [out :: production.blog.com] could not connect to server: Connection refused
** [out :: production.blog.com] Is the server running on host "production.blog.com" (10.210.xxx.xx) and accepting
** [out :: production.blog.com] TCP/IP connections on port 5432?

Any other ideas how to fix this Mongo::ConnectionFailure? The last time I deployed (4-5 months ago everything worked like a charm). Updated to latest rubber version.

Avatar

Hi Ryan,

Thanks for the frontend framework episodes!

In the EmberJs app there was one feature not included in the AngularJs app - disabling the button if all entries are winners.

I implemented that in Angular easily by using ng-disabled="allWinners()" on the button and controller code

ruby
$scope.allWinners = ->
  for entry in $scope.entries
    return false unless entry.winner
  true

however I noticed that it was being called a lot (4 times on load and everytime a character is entered in the textbox).

Is there a way in Angular to only call a bound function when a property is updated, much like Ember does?

Avatar

Awesome railscast!

I've been dealing with this problem a lot lately while building a multi-tenancy app. Corey Haines' view on TDD is very interesting, and I encourage anyone interested to check out his brand new screencast episodes on Clean Coders.

Avatar

Please open an issue on zeus on github

Avatar

Great railscast!

Only one problem with zeus and guard:
When we are using it, randomized with seed is always 0. Any solutions/suggestions? Is not a very big deal nonetheless.

Avatar

Would have liked to see this cast for Test::Unit too... ;-)

Avatar

Thank you! That was a very helpful comment. Ryan should add it to the ASCII cast too

Avatar

Ryan, FactoryGirl.build implictly creates records in database when it has associations. Maybe it's better to use just Model.new for things like validations instead of build()?

Avatar

This is great ! Thank you, I was looking for that.

Avatar

Been finding the solution online for a while. Most of them give the adding the if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then source "$HOME/.rvm/scripts/rvm" ; fi which is a must have.

Even after adding this line , rails still errors. I have to remove .rvm association from export path like you mention here. Solved!

Avatar

As of MiniTest 4.2.0 you can run tests in parallel with parallelize_me.

Avatar

I am follow this video and get this error

ExecJS::RuntimeError in Application#index

Showing /home/william/dev/408-ember-part-1/raffler-after/app/views/layouts/application.html.erb where line #6 raised:

node: symbol lookup error: node: undefined symbol: _ZN2v86LockerC1EPNS_7IsolateE

  (in /home/william/dev/408-ember-part-1/raffler-after/app/assets/javascripts/store.js.coffee)
Extracted source (around line #6):

3: <head>
4:   <title>Raffler</title>
5:   <%= stylesheet_link_tag    "application", :media => "all" %>
6:   <%= javascript_include_tag "application" %>
7:   <%= csrf_meta_tags %>
8: </head>
9: <body>

I tried your source, still this error, I am use openSUSE12.3 and installed nodejs, any thing else I miss?

Avatar

Just thought I'd mention that !! works in bash, but it doesn't auto-expand like that. I wasn't aware of it... hopefully I don't forget before I have occasion to use it.

Avatar

yeah .the speed of test is very important for TDD.. personally i find Spork + sublime Text2 Rspec bundle is really helpful and significantly fast!

Avatar

Rouge is great gem for syntax highlighting and it's written in pure Ruby. I've written blog post with simple Rouge configuration with Redcarpet in Ruby on Rails.

Syntax highlighting in Ruby on Rails

Avatar

to solve this issue, I add "config.serve_static_assets = false" to my config/environments/development.rb

Avatar

thank you very much! 2 days without sleep and so easy solve of this problem :3

Avatar

Quick and dirty way to even add new tags on the fly.

ruby
# Class that is taggable 
def tag_tokens=(ids)
    ids = ids.split(',')
    self.tag_list = Tag.get_tags_from_tokens(ids)
 end

# tag.rb
def self.get_tags_from_tokens(tokens)
    tags = []
    ids = []
    tokens.each do |token|
      if token =~ /<<<(.+?)>>>/
        tags << token.gsub(/<<<(.+?)>>>/, $1)
      else
        ids << token
      end
    end
    tags.concat(Tag.where(:id => ids).map(&:name)) unless ids.empty?
    tags.join(",")
 end

Maybe a better way is to just change the behavior on the client side?

Avatar

figured it out:

tz_names = ActiveSupport::TimeZone.zones_map.values.collect{|z| z.name if z.utc_offset == offset}.compact!
Avatar

Missing this!

ruby
def self.ids_from_tokens(tokens)
    tokens.gsub!(/<<<(.+?)>>>/) { create!(name: $1).id }
    tokens.split(',')
  end

Got this from the source.

Avatar

To be honest, to make APIs rails is not the best options, I prefer to use goliath, https://github.com/postrank-labs/goliath

checkout the performance test (http://jgwmaxwell.com/accelerating-ruby-apis/ ):
Rails 531 request/s
Sinatra 576 request/s
Sinatra::Synchrony 1692 request/s
Goliath 1924 request/s
Cramp 3516 request/s
node.js 3100 request/s

Avatar

at 8:07.. How would I return more than just the name of the object?

I need to supply several other attributes as well although I'm having a hard time finding a simple explanation for using .map to return other attributes as well.

Avatar

Yes. Also if you delete a product_field from the product_type, the data remains.

This is nice if you've got a store that you or a couple of people manage, but wouldn't really cut it for anything larger than that.

Avatar

How to use Handlebars instead of eco in rails ?

Avatar

I am trying to query all of the Users that share a common time zone offset (so I can send them an email at a particular time everyday), and can not figure it out!

User.where(:time_zone => ['list','of time','zone names'])

How do I get a list of the time zone names for a particular offset? I've been tinkering with TzInfo and ActiveSupport::TimeZone.zones_map with limited success.

Am I taking the wrong approach here? I was thinking I could store the GMT offset on the user instead, and query that way?

My google-fu has let me down on this one.

Avatar

Wondering how could this be implemented using ActiveAdmin or Rails Admin.

Avatar

Thanks Ryan for another great episode :)

Word of warning
When using the active_model_serializers gem make sure you override the options in the app controller as this gem will override all JSON rendering not just the ActiveModel you're looking to serialise. So use something like:

ruby
  def default_serializer_options
    { root: false }
  end

Without the above you will have a root node in all of your JSON rendering possibly breaking various client side javascript apps and WebService clients that consume the JSON.

Avatar

Thanks from me too! I wasn't close to finding a solution for this issue until I read your comment.

Avatar

words cannot explain how useful I have found this episode!

I've restructured my first rails site to work this way.

I hit a snag that's bugging me.

For example, in this file:
https://github.com/railscasts/136-jquery-ajax-revised/blob/master/checklist-after/app/views/tasks/_task.html.erb

The delete action is fired with this link:

<%= link_to "(remove)", task, method: :delete, data: {confirm: "Are you sure?"}, remote: true %>

I have incorporated CanCan (another mega thanks, btw!), but this link doesn't work. The user not set when it is passed this way, so cancan authorization fails. I can get around it by using a form and submit instead of the link... but i feel like i'm missing something???

I posted my question here, but thought I'd go straight to the masters for this one...
http://stackoverflow.com/questions/15815522/ruby-on-rails-cancan-user-is-nil-during-destroy-action

Avatar

Thanks ! Just used it today and the gem found a good optimization !

Avatar

Metrical is not maintained anymore, see this commit. According to Readme, it may still work when installed with Bundler and run with bundle exec. Revived MetricFu works like a charm, however I had to add it to Gemfile gem 'metric_fu', group: :metrics, require: false and run with bundle exec too. ruby_parser could not be found otherwise.

Avatar

I was able to "fix" the problem when editing an existing product and not having the second select or having it with all the options. It's looking pretty nasty but it works.

coffee.js
jQuery ->
  loaded_product = $('#product_category_id :selected').text()
  categorys = $('#product_category_id').html()
  $('#product_category_id').parent().hide()
  if loaded_product.length != 0
   brand = $('#product_brand_id :selected').text()
   escaped_brand = brand.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1')
   options = $(categorys).filter("optgroup[label=#{escaped_brand}]").html()
   $('#product_category_id').html(options)
   $('#product_category_id').parent().show()
  console.log(categorys)
  $('#product_brand_id').change ->
    brand = $('#product_brand_id :selected').text()
    escaped_brand = brand.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1')
    options = $(categorys).filter("optgroup[label=#{escaped_brand}]").html()
    console.log(options)
    if options
      $('#product_category_id').html(options)
      $('#product_category_id').parent().show()
    else
      $('#product_category_id').empty()
      $('#product_category_id').parent().hide()
Avatar

The only problem is that when you show the second select, it shows all the options and not only the one it was supposed to.

Avatar

Jobby (https://github.com/Spakman/jobby) is useful for running multiple daemons under a shared environment. Allows you to spin off new processes without reloading entire rails env each time.

Avatar

Thanks for the reply! I didn't notice your solution until now.

Avatar

Thanks, BTW :vote is an action, yours might be different.

Avatar

Disregard this, I had defined fields_for in a custom form builder and it was overriding the default implementation.

Avatar

In fact, because Rails prefers JSON be root wrapped, you need to use this library if you want to have a nice clean controller like Ryan's without heavily customizing ngResource.

Avatar

EDIT: figured out that it's coming from the arguments passed to fields_for here:

    fields = f.fields_for(association, new_object, child_index: id) do |builder|

why doesn't fields_for accept more than one argument?