RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Based on the source code for this episode (I have yet to watch it), you made a typo, should read: auth = env['omniauth.identity']

Avatar

Well there is has_secure_password, not an engine, but does most of the repeatable code. Generally the way I want my controllers and views to behave is dependent on the application. Also it adds more overhead and technical debt to the development and probably won't stack up against OmniAuth or Devise. (Haven't used others)

Avatar

check out my comment below. I've provided an example which daemonizes the mailman server in test / dev and production environments.

Avatar

Hey all. After watching this episode I integrated Mailman into one of our apps. I had to deal with many of the issues described above like daemonizing, testing and so on. I've put together a guide at

http://dansowter.com/mailman-guide/

Hope it helps someone.

Dan

Avatar

I created a mail account for the user my webapp is running with. I forward (selected) e-mails from another account to this one, so mailman can pick them up and process.

Avatar

Did you set Mailman.ignore_stdin to true? I read somewhere that this must be set to run it as a daemon.

Avatar

I tried to use the Daemon gem to run the mailman_server in the background. However, I cannot get it to recognize the rails environment, so I cannot access my models from the mailman_server.

The only way I can get it to run in the background is using:
nohup ./script/mailman_server &

But because there are no start and stop commands, it is difficult to implement in a deployment strategy.

Next try: God to manage the mailman_server

Avatar

I've tried setting up the maildir access (using postfix as my email server), but am having permission problems. The mailman script can't access the maildir messages. If I chmod the maildir, the new messages that get written aren't chmodded, so that doesn't work.

Any ideas on a workaround?

Avatar

The trouble was I had not named the worker file correctly. Sometimes convention over configuration can be a pain to debug.

Avatar

I added a task just like shown and it works great. So I needed another and it refuses to recognize the second one. The first call to Rescue works but the second barf because it thinks it a member of the model. It will not add a second queue, nor will it work if I put it in the first one.

ruby
    if params[:commit] == "Upload File"
      Resque.enqueue(Import360,params[:file].tempfile.path,current_user.id, cookies['Neighborhood'],cookies['Storm'],cookies['Company'])
    else
      Resque.enqueue(FusionTableSync)
    end 

gives the error:
uninitialized constant LocationsController::FusionTableSync
Any ideas?

Avatar

Yes I do have the environment loaded as you've suggested, that's why I don't understand why this doesn't work. I'm going to try bundle exec to run the rake task when I get back to that project and see if that helps at all.

I've also tried with and without attr_accessible, makes no difference, still get the error.

Avatar

Understood - would be good to see more on Metal though :)

Particularly, the common pitfalls when trying to include behaviour that may be strewn across two or three ActionController modules

Avatar

Did you have any luck with this? I am running into the same problem.

Avatar

Hey Ryan,

Is there any reason not to have the method missing check the @object first? As the presenters are usual about a particular model, and delegating a dozen items can be painful.

Something like:

ruby
 def method_missing(*args, &block)
    if @object.respond_to? *args[0]
      @object.send *args, &block
    else
      @template.send *args, &block
    end
  end

Thanks for the great episode!

Avatar

Has anyone got jQTouch working with Rails 3.1+ and the asset pipeline?

Avatar

Ran into this exact same issue a few weeks ago, where I had ActiveAdmin updating records but the Sweeper wouldn't observe the model on normal CRUD. I attempted to have the sweeper get called as an observer but I still couldn't figure my way around it, so I fell back to using Rack::Cache (and updated with suggestions from Ryan's screencast earlier in the week).

Avatar

I agree, I think it would be more practical to be able to attach the sweeper to a model, you may want to expire the same pages or fragments in several controllers, rake tasks ... I suppose the problem is that the views are related and only accessible by the controllers and not models but it feels a little bit weird.

Avatar

I'm wondering why the cache sweepers are tied to the controller.
Some time ago I was writing about this here: http://www.railstoolkit.com/posts/rails-cache-sweeper-confusion

Avatar

+1 for dynamic page caching revised...

Avatar

So, the more I get into it, the more questions I have...

Also not having any luck getting it work with multiple checkboxes. Anyone have that setup working?

Thanks.

Avatar

Anyone using this with the jQuery datepicker? I haven't been able to get it to work - the form just never submits, even though there is a date selected.

Thanks for any help :)

Avatar

I think I followed every step of this screencast, but I could not start unicorn. It seems that the pid files are busy (?). Any idea on how to solve this problem?

I'm using unicorn 4.2.0, which is the newest version of the gem.

When I run " sudo service unicorn restart" I get:

bash
kill: 71: No such process

Couldn't reload, starting '/vagrant/bin/unicorn -D -c /vagrant/config/unicorn.rb -E development' instead
master failed to start, check stderr log for details

And here is my sderr log:

bash
I, [2012-02-02T16:29:54.313595 #2007]  INFO -- : unlinking existing socket=/tmp/unicorn.todo.sock
I, [2012-02-02T16:29:54.316860 #2007]  INFO -- : listening on addr=/tmp/unicorn.todo.sock fd=3
/home/vagrant/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:202:in `rename': Text file busy - (/vagrant/tmp/pids/0.933261511233375.2007, /vagrant/tmp/pids/unicorn.pid) (Errno::ETXTBSY)
        from /home/vagrant/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:202:in `pid='
        from /home/vagrant/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:133:in `start'
        from /home/vagrant/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/unicorn-4.2.0/bin/unicorn:121:in `<top (required)>'
        from /vagrant/bin/unicorn:16:in `load'
        from /vagrant/bin/unicorn:16:in `<main>'
Avatar

I have to agree with @EnricoCarlesso I would like to understand if there is a way to run Pry with Foreman. It seems that it works okay except you cannot see your input when running a web worker plus regular cron-esque worker. I set the unicorn web workers down to 1 so that it wouldn't conflict in that regard, but still the input is an issue.

Avatar

Thanks for taking the time to explain this, it's always nice to see all the options and how it affects the http header. Keep up the good work!

Avatar

Thanks, bitencode. This works great!
And thank you all, too!!

Avatar

Did you manage to get a solution for this?

Thanks.

Avatar

On using the above procedure, I get the following error message:

undefined method `error_message' for #ActionView::Helpers::FormBuilder:0x9fa7f54

Can anyone help me?? Thanks in advance..!!

Avatar

Is there a way to do API versioning and inheritance with jbuilder?

Avatar

Right. I get why it wasn't working.

My question is how I could bypass the rack::cache layer for logged in users.

I could certainly do #169's approach, but I'd far rather optimize for the 99%, leaving my code pretty much in tact, and just serve up the site to the very small % of logged in users. My actual in app caching is optimized enough I'm not too worried.

I will look into #305, but I've scoured the net and can't figure out a way to disable rack::cache for requests based on cookies, which is what I would need to do here.

Avatar

It seems like an appropriate episode to revise… Thanks Ryan!

Avatar

Setting :public => !user_signed_in? won't work, because when the first user comes, she won't be signed in and so the cache will be set, and when it gets set it won't hit the app to check it again.

I imagine you would have to override some behaviour in the rack::cache itself or put another middleware before it. But I don't think it would be worth it.

You should try the solution form epsiode #169 mentioned above. If you really want to get dirty with middlewares you can try to mix it with episode #205 on authentication with Warden, but as I said I doubt it's worth the effort. You'll just get into a mess that way.

Avatar

I had the same issue. Facebook just doesn't seem to work with localhost unlike Twitter. But I did test it against a public ip that I own and it works as expected. If you don't have a pulbic ip you can try going with some kind of dynamic dns solution.

You can also try looking up this Stackoverflow topic, but your settings seem correct. Maybe lvh.me will work though.

Avatar

+1 to revising episode 169.

Does anyone know if you can simply bypass rack::cache for logged in users and still take advantage of http caching for 99% of my users that show up anonymous?

I set :public => !user_signed_in? accordingly, but rack::cache will still serve a public cached copy if it already had one to logged in users.

Any help would be appreciated! Thanks for the awesome railscast as always!

Avatar

I was hoping you would do a railscast on Jbuilder! How about one on Grape, it's got some pretty cool features. If you wanted to do a 5min Pro on Grape I'd be ok with that :)

Avatar

I have followed the omniauth devise facebook app as explained by Ryan in episode 235.After the user authorizes we are getting the error at http://localhost:3000/auth/facebook/callback?code=13444...

The following are the facebook settings :
App Domain : localhost
siteurl: http://locahost:3000/
canvas url: http://localhost:3000/auth/facebook/

I have also tried using 127.0.0.1 in the place of locahost for facebook settings, but i am getting a invalied domain error on facebook settings page.

please tell me where am i going wrong?

Avatar

Bad Luck..Date picker is coming but still the values are changing only in the first text field only...every other text fields remain empty....!!! Is anyone out there can help me???

Avatar

The show notes have 'views/articles/show.json.builder' as the one path, but it should be '.jbuilder'

Very timely episode. I'm implementing it now!

Avatar

Great tuto ! Useful for everythin. Thanks
Please note that it should be :

bash
if [[ -f Rakefile ]];then
#....
fi

and not

bash
if [[ -f Rakefile]];then
#....
fi
Avatar

Make sure your Rake task is loading the full Rails environment: task :foo => :environment. It should have access to the key/value store then.

Avatar

It depends on what you're doing in the middleware, but usually it will only add a quick "if" condition and a couple method calls to the stack. In theory it is slightly slower but nothing that will be noticeably slower.

Avatar

I am trying to avoid renaming the titles of the episodes when I revise them, so I understand that can make it a little misleading.

Avatar

I just discovered RABL - me gusta!

Avatar

RABL is similar, and I will likely do an episode on it in the future since it is different enough from Jbuilder. What I like about Jbuilder is its simplicity (it is just two small files). But RABL has more to offer in its interface.

Avatar

Good question. You can't use the cache helper method because that is designed to work with ERB. However you can use the read_fragment and write_fragment methods to manage the cache directly.