RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Even if the JS and CSS is cached, the browser won't start parsing and interpret until your page shows the inclusion. If your page takes 10 seconds to load, that will take 10 seconds. If are using streaming, that happens right away.

Avatar

To that, have a part of the page update with status, you'd use ajax and polling on HTML 4 and sockets on HTML 5 (comet?). Rails is not good at it.

Avatar

I thought the idea of streaming wasn't to show the user a part of the page, but to have the browser start parsing and interpreting CSS and JavaScript while the server is still running that complex and heavy query.

Avatar

Yeah, I'm getting the same. It means that we have no enable streaming per action with an explicit call. Looks ugly, I wonder if streaming is regarded as an exception.

Avatar

When running the curl command I get this error:

curl: (56) Received problem 3 in the chunky parser

Anybody knows what's going on?

Avatar

hi,
i always get into problems testing the content of emails send with delayed_job. it should be pretty common to do so right ? haven't found any good solution for that... tips ?

why does that not work:

ruby
  it "emails user when requesting password reset" do
    ...
    Delayed::Worker.new.work_off
    last_email.to.should include(user.email)
  end

?

Avatar

Twitter callback URL needs to be set (or else OAuth throws 401 exception): http://goo.gl/EHCqE.

Avatar

What do you mean? Doesn't

tailf log/development.log

fits your needs?

Avatar

What is the HTML supposed to look like again?

Avatar

If you're using Guard you can also use the guard-process gem. It doesn't have all of the features Foreman has, but it does allow you to easily specify when your processes need to be restarted in standard Guard fashion.

Avatar

How do you think this compares to the terminitor gem...I have been using it to start up my environments.

Avatar

You probably want to add something like this if you don't want to break xml or json output, (with responds_to blocks):

ruby
def prepare_for_mobile
  if request.format == 'text/html'
    session[:mobile_param] = params[:mobile] if params[:mobile]
    request.format = :mobile if mobile_device?
  end
end
Avatar

Which post that you mentioned here?

I meet the same problem, removed h() and get fixed

ruby
def link_to_add_fields(name, f, association)
 ...
 ...
 link_to_function(name, "add_fields(this, '#{association}', '#{escape_javascript(fields)}')")
end
Avatar

But, which file is included first? Which file is implicitly referenceable by "someFile.js" vs explicitly? Alphabetically by directory?

Avatar

can someone update the commands for Rails 3.1?

Avatar

I have Foreman set up for Heroku, but didn't think of using it in my development environment. Is there a way to see the usual rails server logs? That's the only thing keeping me from switching my s alias from rails server to foreman start. Any ideas?

Avatar

Hi,

I'd like to clean up the URLs generated by the searches, does anyone know how to do this?

At the moment I'm getting something like this:
http://127.0.0.1:3000/events?utf8=?&search%5Btown_name_equals%5D=&search%5Bgenre_name_equals%5D=DJ+Music&search%5Bdate_equals%5D=&commit=Search

Avatar

js on Rails 3.1.0.rc6 can't work.why?

Avatar

I was wondering wouldn't it be easier to just create a rake task (boot.rake)?

You can easily pass the environment type to your commands so you'll be able to use it on production / staging as well.

Avatar

Short and good intro to foreman. But a bit more explanation on the Procfile itself would have been good for many people i guess.

Because if you know that this is the prefered way to have heroku know about your processes it opens a whole new world ;-)

Here is a good Article about that: http://devcenter.heroku.com/articles/procfile

Avatar

Has anyone had any success with using the "binding.pry" feature with Pow?

Avatar

I added a dirty instance_eval hack to make Hirb.disable/enable work in-session:

https://gist.github.com/1177892

cldwalker is probably opinionated about Ripl, but I'll ask if he'll accept a patch to Hirb for built-in Pry support.

Edit: Just found this issue where he indeed says he doesn't want to support more shells in the gem itself (and you guys originally shared this .pryrc snippet =]).

Avatar

Thank you! I took Pry for a spin several weeks ago but didn't take the time to fully explore getting Hirb working so I haven't been using it for Rails' console. I think I will now :-)

Avatar

Hi all,

Is it possible to use page caching, but then pull in an entire form via ajax so that it has a fresh authenticity token?

Is that inadvisable for any particular reason?

Thanks,
Raviv

Avatar

How can I render nested partial with this plugin. Only partial property_manager_fields is rending but nested partial login_fields is not being rending with click on add_to_link using jQuery
_form.html.erb
<%= f.fields_for :property_managers do |builder| %>
<%= render "property_manager_fields", :f => builder %>
<% end %>
_property_manager_fields.html.erb
<%= f.fields_for :login do |builder| %>
<%= render "login_fields", :f => builder %>
<% end %>
<%= f.text_field :phone %>
<%= link_to_remove_fields "remove", f %>

_login_fields.html.erb
<%= f.text_field :username " %>

Avatar

As per this example How can I add Question with 4 Answers with single click on

<%= link_to_add_fields "Add Question", f, :questions %>

Avatar

Today I needed to implement role-based authorization. I reviewed a few gems, and the cancan gem looked like the easiest to implement (and it had the most downloads and most forks on github).

It was a true pleasure to integrate this into my app! Works like a charm. Simple, and effective.

Now I need to remove the old half-finished, hard-coded authorization logic, and that may actually be more work!

Thanks Ryan, love your screencasts. This gem was so easy to use, I didn't even bother watching the screencast :-)

Avatar

try the latest master from github, this changeset added generic(Kaminari AND WillPaginate) pagination support:

merge from pull #67

I <3 Kaminari w/ Sunspot.

Avatar

The biggest obstacle with setting up Sunspot in a production environment was just setting it up with a process monitor, like monit. I recently submitted a patch for Sunspot so that you can set the directory for the PID file, and it was accepted, so there's really nothing left to stop you from using 'rake sunspot:solr:start' as a startup task.

See:Configuring Solr

Avatar

A few options at present:

https://github.com/AndrewO/ruby-debug-pry

Also you may be interested in:

https://github.com/mon-ouie/pry_debug

Another thing i would like to do would be to bring ruby-debug commands into Pry itself, rather than having to use Pry from inside ruby-debug. This will be a task for the future (but should not be too difficult).

Avatar

I use binding.pry to break the app (start webrick with --debugger) but couldn't find how to step or next at the Pry prompt, though I can 'exit' to let the app continue. Is there anyway to have Pry work with ruby-debug?

Avatar

This is true for me as well. Everytime Ryan is executing tests they run 4 times faster than with my computer. I know that you can speed up tests with spork, but Ryan doesn't do it in his episode and he gets 4 times faster results:

With the repo of this episode the tests run in 2 seconds on my pc.
On Ryans PC they run in 0.5 seconds or less

Avatar

Hey Ryan, I have been trying to see if there is a way to somehow integrate cancan's ability model into this Sunspot search. Any thoughts on how it might be done?

Avatar

Thanks for the great screencast.

For those who wish to use Hirb with Pry add the following to your ~/.pryrb file

ruby
require 'hirb'

Hirb.enable

Pry.config.print = proc do |output, value|
  Hirb::View.view_or_page_output(value) || Pry::DEFAULT_PRINT.call(output, value)
end
Avatar

It should mostly work fine in 1.8.7 MRI and 1.8.7 RBX; i even backported Proc#source_location and Method#source_location so show-method and show-doc should work too, the only thing that doesnt work in 1.8.7 is source retrieval of methods defined inside the REPL; but it should be relatively rare you'd do this (i hope) :)

Avatar

Did you ever figure this out? I'm getting the same error.

Avatar

For Windows users, the amazing reloading mechanism on edit-method works fine when using GVIM and set EDITOR=vim

Avatar

After editing the file in vim and exiting type load _file_ or reload-method Your#method_name to manually reload the file. (where _file_ is a special local representing the last file accessed by Pry)

Avatar

I once got some colorful working with ansicon and those .irbrc . Some more fiddling may be required, hope that helps, Frank

ruby
require 'rubygems'
require 'win32console'
require 'term/ansicolor' 
include Win32::Console::ANSI
include Term::ANSIColor
require 'wirble'
Wirble.init
Wirble.colorize
Avatar

Dont forget to mention that you need to install memcached in your system. It wasnt obvious to me and nothing worked until I ran
apt-get install memcached

Avatar

I like vim but my colleagues not loving it and i can't use it as default on common server. But when i run pry $EDITOR=vim it still use nano =(

Avatar

you can set the environment variable $EDITOR in your shell instead and Pry will use that. Why do you want to avoid setting Pry.config.editor btw?

Avatar

Is there any way to let methods like "show-method, edit, etc." use vim without binding to default editor?

Avatar

@adnan4721 you should start Faye using Thin (as a separate process). You'll find a Rackup example for that on the Faye site: http://faye.jcoglan.com/ruby.html

Put your config into faye_config.ru and start it with the following command:
thin -R faye_config.ru start

Avatar

I get the error, file "lin" not found
any ideas?

Avatar

Asset pipeline is awesome, but how to deal with scripts like lightbox or wysiwyg, that distributed in one folder with local paths for included js, css and images? How to deal with this via asset pipeline?

Avatar

hi,
I was having some issues thought i might share it here.
I am working on a rails3.1.0.rc6 app using the latest Omniauth gem to authentication user by tiwtter and facebook

But like the demo here on

ruby
def create 
  render :text=>request.env['omniauth.auth'].to_yaml
end

is giving null response

but changing it to

ruby
def create(auth=request.env['omniauth.auth'])
  render :text=>auth.to_yaml
end

seems to work fine.
I am not sure why this is happening

Avatar

If i try
IRB = Pry
I get this:
ruby-1.8.7-p334/lib/ruby/1.8/irb/workspace.rb:19:in initialize': undefined methodconf' for Pry:Class (NoMethodError)
from /Users/dragos/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/irb/context.rb:27:in new'
from /Users/dragos/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/irb/context.rb:27:in
initialize'
from /Users/dragos/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/irb.rb:100:in new'
from /Users/dragos/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/irb.rb:100:in
initialize'
from /Users/dragos/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/irb.rb:59:in new'
from /Users/dragos/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/irb.rb:59:in
start'
from /Users/dragos/.rvm/rubies/ruby-1.8.7-p334/bin/irb:17