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.
So, I've yet to see a good description of how to make caching play nicely with a user login status panel. You know, the little "logged in as John Smith" div that every Devise-based Rails app seems to have.
Obviously, you don't want this to be cached publicly, but then you lose all of that wonderful public cache goodness with Rack::Cache. I saw the conditional content bit at the end for public caching, but I'm not sure exactly how that would work -- does that mean that anyone who hits this page simply wouldn't see those elements? If so, how do you render flash notices or login status?
This -- the fact that there's usually just one or two parts of a complicated page that I DON'T want to cache publicly -- is what stops me from using public caching in Rails. I'd love to hear comments; it's quite possible that I am simply misunderstanding how it works. Maybe some more quality time with curl would help me...
Hi, I am fairly new to both rails and heroku. Based on ur suggestion, I researched quite a bit on how to create rake task and call Mailman::Application.run, but was not able to find any good examples. I'd very much appreciate if you can share some sample code around this. Thanks!
Maybe I'm stupid or maybe I'm just a newbie (this for sure), I've tried to put the costant in the environment.rb file and use it from the application but I get an "uninitialized constant" error, I understand YAML files are a better place to put configuration but why I get this error? (I'm using Ruby 1.9.2 and Rails 3.1.3, probably something changed since the screencast)
Check out this fork of TableBuilder if you're still looking for something like this. It's been gemified so it's simple to use with bundler and won't result in any deprecation warnings with Rails 3.2
I decided to use Kaminari in one of my projects I am updating to Rails 3.1. Just in case anyone has SEARCH functionality in their application, the original code probably looks like this:
if params[:search].nil?
@users_paginated = [].page(params[:user_page])
elsif params[:search].blank?
@users_paginated = [].page(params[:user_page])
else
@users_paginated = user_search_method # this is just a method I created for my project.
end
Your new code should probably look like this:
if params[:search].nil?
@users_paginated = Kaminari.paginate_array([]).page(params[:user_page])
elsif params[:search].blank?
@users_paginated = Kaminari.paginate_array([]).page(params[:user_page])
else
@users_paginated = user_search_method # this is just a method I created for my project.
end
OR, if you wanted to return the first group of users in the database when no param is entered or if the result is blank, you could do the following:
@users_paginated = User.page(params[:user_page]).per(10) # This would return the first 10 users.
Hi, just wanted thank you for a great episode, and point out that the ASCII cast states that I should use view_content rather than view_context. Took me a while to figure that out =)
It've been confused as well, that the sprocket directive //= require_tree . in app/assets/javascripts/application.js does not include javascripts in /vendor/assets/javascripts. But your solution works well. Same goes for stylesheets, put this line in your app/assets/stylesheets/application.css:
css
*= requirevendor
and create a file /vendor/assets/stylesheets/application.css containing:
Is it just me or can we not access the new key/value store attribute in a rake task? I'm trying to set values of some keys in a kv store attribute, and I'm getting an unknown attribute error.
However, I have no such issue when I access or try to set the same attributes via the console.
I also tried to set values in the class initialize method, which works fine in Rails and the console. I get the same error when the class in initialized in a rake task.
Great screencast! Is it possible to add count of subelements to json/xml output? e.g. photo has many comments, and I want to add comments_count to /photos.json ?
can anybody please help me. how to configure mailman on production.
should i need to keep my production terminal allways open after typing script/mailman_server.rb
I would also recommend you check out Pusher. It is a commercial service, but provides a lot of great value out of the box (and very easy to get started with for free).
It would also probably make another great screencast.
-Scott
P.S. I have no affiliation with Pusher....I am just a big fan. :)
If we add a few middle on the top of the stack and gain performance for those items, will it slow down the rest of the app because the middleware stack is now deeper?
Is there anyway for me to use both friendly_id and the record id? I'd like to use friendly_id in my consumer-facing URLs, but the record id in my admin URLs... is there anyway to do that?
EDIT: Ok, I see that I can manually change the parameter in the URL, and it still works as expected.. but my path helpers all use the friendly id, e.g.:
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?
Check acts_as_api, really useful and modular. You'll define templates once for json and xml.
Well, one way is caching the whole page and loading user specific info like the logged in as box via ajax.
I was wondering the same thing. Right now I use partial caching with memcache which has helped a lot.
So, I've yet to see a good description of how to make caching play nicely with a user login status panel. You know, the little "logged in as John Smith" div that every Devise-based Rails app seems to have.
Obviously, you don't want this to be cached publicly, but then you lose all of that wonderful public cache goodness with Rack::Cache. I saw the conditional content bit at the end for public caching, but I'm not sure exactly how that would work -- does that mean that anyone who hits this page simply wouldn't see those elements? If so, how do you render flash notices or login status?
This -- the fact that there's usually just one or two parts of a complicated page that I DON'T want to cache publicly -- is what stops me from using public caching in Rails. I'd love to hear comments; it's quite possible that I am simply misunderstanding how it works. Maybe some more quality time with curl would help me...
+1
check out a gem called "representative_view" https://github.com/mdub/representative_view
Thanks Ryan, very easy to understand. Do you plan on making an episode on Backbone.js soon?
Hi,
my issue is not really related to this railscast but I'm also getting :3000:3000 when using _url helpers.
What you did could solve this issue? So yes, could you explain, I don't find this 'with_subdomain' function anywhere.
Thanks.
I have used
ActiveModel::Serializers::JSON
module to make a serializer/presenter class and I like this approach better than Jbuilder.There is XML Builder that comes bundled with Rails ("builder" gem)
Is there any gem for generating xml representation in such kind of way?
Is it possible to do fragment caching with Jbuilder?
Thanks for reporting that! The ASCIIcast has been corrected.
is your partial in a different view directory than the one it's called from?
Why in god's name do we need to use global variables? How is this an acceptable practice?
I'd love to be convinced that this is a good way to develop.
Hi, I am fairly new to both rails and heroku. Based on ur suggestion, I researched quite a bit on how to create rake task and call Mailman::Application.run, but was not able to find any good examples. I'd very much appreciate if you can share some sample code around this. Thanks!
OK...the "problem" was I have to restart the server and the constant "appears" :)
Maybe I'm stupid or maybe I'm just a newbie (this for sure), I've tried to put the costant in the environment.rb file and use it from the application but I get an "uninitialized constant" error, I understand YAML files are a better place to put configuration but why I get this error? (I'm using Ruby 1.9.2 and Rails 3.1.3, probably something changed since the screencast)
Thank you very much and sorry for the noise ;)
What about separating into partials and then:
<%= render "myview_#{Rails.env}" %>
Then have the following partials:
myview_demo
myview_production
etc...
Check out this fork of TableBuilder if you're still looking for something like this. It's been gemified so it's simple to use with bundler and won't result in any deprecation warnings with Rails 3.2
I decided to use Kaminari in one of my projects I am updating to Rails 3.1. Just in case anyone has SEARCH functionality in their application, the original code probably looks like this:
if params[:search].nil?
@users_paginated = [].page(params[:user_page])
elsif params[:search].blank?
@users_paginated = [].page(params[:user_page])
else
@users_paginated = user_search_method # this is just a method I created for my project.
end
Your new code should probably look like this:
OR, if you wanted to return the first group of users in the database when no param is entered or if the result is blank, you could do the following:
I hope this helps someone.
Hi, just wanted thank you for a great episode, and point out that the ASCII cast states that I should use view_content rather than view_context. Took me a while to figure that out =)
Thanks.
+1
It've been confused as well, that the sprocket directive
//= require_tree .
in app/assets/javascripts/application.js does not include javascripts in /vendor/assets/javascripts. But your solution works well. Same goes for stylesheets, put this line in your app/assets/stylesheets/application.css:and create a file /vendor/assets/stylesheets/application.css containing:
Is it just me or can we not access the new key/value store attribute in a rake task? I'm trying to set values of some keys in a kv store attribute, and I'm getting an unknown attribute error.
However, I have no such issue when I access or try to set the same attributes via the console.
I also tried to set values in the class initialize method, which works fine in Rails and the console. I get the same error when the class in initialized in a rake task.
Any ideas?
Great screencast! Is it possible to add count of subelements to json/xml output? e.g. photo has many comments, and I want to add comments_count to /photos.json ?
In ASCII cast there is a '=' missing between self.row_colors AND ["DDDDDD","FFFFFF"]
BTW
Great Cast!!!
can anybody please help me. how to configure mailman on production.
should i need to keep my production terminal allways open after typing script/mailman_server.rb
Really great. I customize it to use the new html5 and have an autocompletion on association without javascript.
For me the application does not show the near by locations, even if I run the code as is..
Anyone had similar problems?
Would appreciate any help on how to fix this.
Thx
Hi Ryan,
Great screencast as usual.
I would also recommend you check out Pusher. It is a commercial service, but provides a lot of great value out of the box (and very easy to get started with for free).
It would also probably make another great screencast.
-Scott
P.S. I have no affiliation with Pusher....I am just a big fan. :)
Also interested in this, hope Ryan can share some light on this question and the one above ;)
Is it possible to use cancan or other authorisation methods with elasticsearch or tire?
same thing
Thanx 'ed'..Your code for dynamic date fields really helped me...I've lost my 1 week over this....Thank you..!!
If we add a few middle on the top of the stack and gain performance for those items, will it slow down the rest of the app because the middleware stack is now deeper?
How can I push only the messages sent between the people in a one-to-one chat? Should I create a channel for every pair of users?
did you run
rake db:migrate
?Nevermind... just figured out that I was passing in
user
instead ofuser.id
.Is there anyway for me to use both friendly_id and the record id? I'd like to use friendly_id in my consumer-facing URLs, but the record id in my admin URLs... is there anyway to do that?
EDIT: Ok, I see that I can manually change the parameter in the URL, and it still works as expected.. but my path helpers all use the friendly id, e.g.:
edit_admin_user_path(user.id) #=> /users/some-friendly-id/edit
How can I get this?
That was really helpful, thanks!
fixed it by using
@message = Message.new
@message.parent_id=params[:parent_id]
instead of
@message = Message.new(:parent_id => params[:parent_id])