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
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).
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.
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.
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
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>'
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>'
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.
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.
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.
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.
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!
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 :)
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.
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???
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.
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.
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.
Great point. Sometimes you can get by with making the status panel more generic such as "My Account" so it can work for any situation. However that isn't always wanted.
Alternatively you can use JavaScript to load the dynamic content. See Episode 169: Dynamic Page Caching on how to do this. I plan to revise that episode in the near future.
Did you have any luck with this? I am running into the same problem.
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:
Thanks for the great episode!
Has anyone got jQTouch working with Rails 3.1+ and the asset pipeline?
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).
Thank you Ryan, this screencast is very informative for me.
+1
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.
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
+1 for dynamic page caching revised...
You can look into Sinatra or Padrino
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.
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 :)
This is great.
Thanks a lot Ryan!
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:
And here is my sderr log:
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>'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.
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!
Thanks, bitencode. This works great!
And thank you all, too!!
Did you manage to get a solution for this?
Thanks.
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..!!
For the sake of the future.
http://wiki.macromates.com/Troubleshooting/EditInTextMate
Is there a way to do API versioning and inheritance with jbuilder?
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.
Another awesome screencast Ryan!
It seems like an appropriate episode to revise⦠Thanks Ryan!
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.
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.
+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!
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 :)
"I have some Kryptonite for you Superman!" genius
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?
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???
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!
I agree with julescopeland! I was just thinking about this topic.
Screencast is awesome.
Thanks Ryan.
You rock so hard.
Great tuto ! Useful for everythin. Thanks
Please note that it should be :
and not
Make sure your Rake task is loading the full Rails environment:
task :foo => :environment. It should have access to the key/value store then.Fixed, thanks!
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.
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.
I just discovered RABL - me gusta!
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.
Good question. You can't use the
cachehelper 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.Yep, I show how to do this in episode 169.
Great point. Sometimes you can get by with making the status panel more generic such as "My Account" so it can work for any situation. However that isn't always wanted.
Alternatively you can use JavaScript to load the dynamic content. See Episode 169: Dynamic Page Caching on how to do this. I plan to revise that episode in the near future.
Yes it is but RABL offers you JSON and XML.
Personally, I preferred RABL. I guess its up to everyone.
Ignore me. Got it sorted now. Added
gem 'bcrypt-ruby', :require => 'bcrypt'to my gemfile and it works perfectly :)Can't you just use an ordered list
<ol>?This is what I do and it works quite well.
Thanks for that link murdoch. Useful little Rack example.
I'm getting the same problem.
gem 'bcrypt-ruby'is in my gemfile and I've runbundle install. Still no joy.I'm on OSX and running Ruby 1.9.2 (via Rbenv) and Rails 3.2.0.
Any ideas?
Is jBuilder similar to RABL? (I think it is...) If so - what are the pros/cons of jBuilder vs RABL?