As an aside, a tend to create a tsv column for any models that I'm going to be having a full text search on and using before update / insert triggers for maintenance.
This way, the expense of the to_tsvector happens only on writes and I don't need to have multiple indexes, just the one index on the whole vector.
Obviously this is not the solution for a volatile schema as you'll need to recreate the triggers and recreate the tsv column if you want to search for more things, but one where the schema and search is fairly stable its ideal.
"Since Rails 3 came out, I have no longer used Inherited Resources. I have found that the responders abstraction and custom Rails generators offer the perfect balance between hiding and showing too much logic. That said, I suggest developers to make use of the responders gem (at github.com/plataformatec/responders) and no longer use Inherited Resources."
Nice one Ryan! I've been thinking about switching ot PG.
If you do a follow-up, could you cover how to do a PG version of a mysqldump please? And then how to put such a dump back into a (new) DB?
(Or some other way to backup/restore a db, thanks!)
A small side note: On Debian/Ubuntu/Mint Linux, you'll need libpq-dev (Postgres headers) to install the pg gem, not libpg.... That annoys me every time I setup a new server... ;-)
You can use Chef to install Ruby on the server instead of having to log in and set it up yourself.
You can use knife bootstrap host instead of logging in and installing everything chef needs manually. Chef even allows you to build your own custom bootstrap script based on what type of Linux machine your using.
Yes. I think the convention is to use sweepers/observers though. Assuming you want it async that is, otherwise just call your cache clear method directly and make it more obvious what you're trying to do.
Can you run your application which is using CopyCopter client on Heroku as well, so that your client(s) can edit the app in the cloud? Or does the client app have to be locally hosted?
Is there somewhere that there is information on this?
I ask as I'm looking at working in a remote team for a piece of OSS work, and this would provide a quick mechanism for the development team to receive client feedback.
P.S. Another great screencast Ryan. Keep them coming.
P.P.S I'm trying to use Cucumber with sorcery and a screencast on using Cukes with authentication from scratch would be great in my opinion as must Cuke tutorials assume you are already logged in and have been authenticated.
Great cast. This was extremely helpful, as always. Thanks for this.
I have still one question, though: Now after I've created my PDF through Prawn, how would I go about caching the PDF? Has anyone any experience with this?
This is exactly the episode I was looking for. Ryan Bates is a leg-end!
One thing I'm not sure about:
Should there be a call to rbenv rehash inserted some where in one of the capistrano recipes. I tried adding paperclip to a project and deploying it but the application is not picking it up when it starts up. The recipe does run the bundle command to install new gems when doing a standard cap deploy but from what I can see from reading around I suspect the rbenv rehash needs to be called after the bundle command and I'm not sure if it is included in the recipe provided by Ryan in this example. If this is the case it would explain why my app is not picking up paperclip and is not starting. I'm not sure myself where or how I would make the call to rbenv rehash in the capistrano recipe.
Perhaps some would be kind enough to point me in the right direct?
Hi Ryan, I'd like to congratulate you for this wonderful job at railscasts.com. I'd love to see a screencast on how this Http caching techniques would play with something like Varnish cache or any other reverse-proxy/cache system.
having issues testing my helpers using Test::Unit. It seems that when a helper method uses url_for (i.e. link_to) it doesn't call the modified url_for method in the UrlHelper module.
I've added
ruby
classGenericHelperTest < ActionView::TestCase
include UrlHelper
include Rails.application.routes.url_helpers
end
I'm using acts-as-taggable-on and was wondering how I might go about creating a new tag if one wasn't found already. I've tried several things and I keep getting an error where its searching for a tag with an id of 0 whenever it doesn't know about the tag already
Thanks Ryan, have wanted to tune my logs a little more. Good jump off point.
@Milovan: I've had this (raw HTML) issue too. I thought it was being caused by Glimmer Blocker, but having removed Glimmer, the problem persists (on Safari, for me).
I'd like to use datatables but I'm using an api where not all columns are sortable and it has a weird way of passing the column argument, rather than column and direction i have to pass columnIsdesc=true or false or not pass it.
Here is another bug (on Chrome at least). If you navigate away from this comments page (by entering url) and then press browser "Back" button, you'll see raw HTML.
I want to ask a question that how can i upgrade bundler on production system? So i upgrade my bundler without problem from 1.0.10 to 1.1.0 as follows.
bash
# gem install bundler --version='1.1' --no-rdoc -no-ri
# gem uninstall bundler
Select gem to uninstall:
1. bundler-1.0.10
2. bundler-1.1.0
3. All versions
> 1
You have requested to uninstall the gem:
bundler-1.0.10
jquery-rails-1.0.18 depends on [bundler (~> 1.0.0)]
kaminari-0.10.4 depends on [bundler (>= 1.0.0)]
orm_adapter-0.0.7 depends on [bundler (>= 1.0.0)]
orm_adapter-0.0.5 depends on [bundler (>= 1.0.0)]
rails-3.0.11 depends on [bundler (~> 1.0)]
rails-3.0.7 depends on [bundler (~> 1.0)]
rails-3.0.5 depends on [bundler (~> 1.0)]
thor-0.14.6 depends on [bundler (~> 1.0)]
If you remove this gems, one or more dependencies will not be met.
Continue with Uninstall? [Yn] Y
Successfully uninstalled bundler-1.0.10
# bundle update
# bundle package
One thing I noted when trying to implement datatables with server-side processing is that the SQL queries on search aren't as fuzzy as the default datatables search function. If you're going server-side, definitely check out other search solutions.
Hi guys, I have been trying to get everything mentioned in the video but for some reason I can't get my omniauth data stored in a session for when a new user registers. Everything else works, I can add an authentication to a user and sign in with it.
in authentications_controller.rb I have:
def create
...
else
session[:auth] = auth.except('extra')
redirect_to new_user_registration_path
end
end
in registrations_controller.rb I have
def build_resource(*args)
super
if session[:omniauth]
@user.apply_omniauth(session[:omniauth])
@user.valid?
session[:omniauth] = nil
end
end
In the terminal log I can see that the authentications for the user are getting built but once the user registers the authentication does not save and he has to add it again. What am I doing wrong? I can't figure it out!
Ryan wrote this deploy.rb file with Ruby 1.9 syntax for hashes, and you appear to be using Ruby 1.8. I was also using Ruby 1.8. Here's how I fixed it:
At each place where it says "roles: :{role}", you need instead ":roles => :{role}".
The same is true for that "except: {no_release: true}" formulation, which needs you to add two hash arrows. It should become ":except => { :no_release => true }".
I was having the same problem and moving the require_tree means that the Raffler and Backbone not defined errors have gone. However the route is still not calling the Index function - so I don't see any alert on loading the page. Any ideas of where I can take it from here?
I was having the same problem as Cenature and moving the require_tree to the bottom of the page helped, and now I do not see any errors. However the index function is still not being called so I do not receive the alert 'home page' on loading the application. Anybody else with the same problem?
Can someone kindly advise how I can resolve this error? I got this after installing the gemfile. I am new to rails and ruby. Appreciate it!
ExecJS::RuntimeError in Articles#index
Showing C:/Sites/dummy/app/views/layouts/application.html.erb where line #6 raised:
SyntaxError: octal escape sequences "\00" are not allowed on line 512
(in C:/Ruby193/lib/ruby/gems/1.9.1/gems/mercury-rails-0.3.1/vendor/assets/javascripts/mercury/regions/editable.js.coffee)
Sorry but I think this episode is far below average level: nearly everything is obvious and can be googled easily.
Nice!
As an aside, a tend to create a tsv column for any models that I'm going to be having a full text search on and using before update / insert triggers for maintenance.
This way, the expense of the
to_tsvector
happens only on writes and I don't need to have multiple indexes, just the one index on the whole vector.Obviously this is not the solution for a volatile schema as you'll need to recreate the triggers and recreate the tsv column if you want to search for more things, but one where the schema and search is fairly stable its ideal.
AWESOME!
First time i'd heard of taps makes it a ton easier to make the jump!
How does each episode come out right at the time I need it? It's happened so many times it's a little frightening.
Deprecation notice and advice from the author:
"Since Rails 3 came out, I have no longer used Inherited Resources. I have found that the responders abstraction and custom Rails generators offer the perfect balance between hiding and showing too much logic. That said, I suggest developers to make use of the responders gem (at github.com/plataformatec/responders) and no longer use Inherited Resources."
Nice one Ryan! I've been thinking about switching ot PG.
If you do a follow-up, could you cover how to do a PG version of a mysqldump please? And then how to put such a dump back into a (new) DB?
(Or some other way to backup/restore a db, thanks!)
Edit: just found:
http://linux.die.net/man/1/pg_dump
http://linux.die.net/man/1/pg_restorev
BTW i should also add... i <3 the taps gem!!
I recently switched from MySQL to PostgreSQL and couldn't be happier. The performance i get out of pg is great!
I found that migrating my data from MySQL to pg was a challenge though and i wanted to point anyone who's currently going through that @ this post: http://ruby.zigzo.com/2011/12/03/migrating-data-from-mysql-to-postgresql/
Basically it's a record of how I was able to migrate data from mysql -> pg using a gem by Max Lapshin.
Great episode!
A small side note: On Debian/Ubuntu/Mint Linux, you'll need
libpq-dev
(Postgres headers) to install thepg
gem, notlibpg...
. That annoys me every time I setup a new server... ;-)You can use Chef to install Ruby on the server instead of having to log in and set it up yourself.
You can use
knife bootstrap host
instead of logging in and installing everything chef needs manually. Chef even allows you to build your own custom bootstrap script based on what type of Linux machine your using.Check out
knife help bootstrap
Yes. I think the convention is to use sweepers/observers though. Assuming you want it async that is, otherwise just call your cache clear method directly and make it more obvious what you're trying to do.
Can you run your application which is using CopyCopter client on Heroku as well, so that your client(s) can edit the app in the cloud? Or does the client app have to be locally hosted?
Is there somewhere that there is information on this?
I ask as I'm looking at working in a remote team for a piece of OSS work, and this would provide a quick mechanism for the development team to receive client feedback.
P.S. Another great screencast Ryan. Keep them coming.
P.P.S I'm trying to use Cucumber with sorcery and a screencast on using Cukes with authentication from scratch would be great in my opinion as must Cuke tutorials assume you are already logged in and have been authenticated.
I wrote a colorful logger class.
It uses term-ansicolor gem and intends to be used in multi-process environment where pid is colored to make it easier to distinguish processes.
You can put that file in
lib/
and use colorful logger directly like:or just pick some code and patch SimpleLogger.
Great cast. This was extremely helpful, as always. Thanks for this.
I have still one question, though: Now after I've created my PDF through Prawn, how would I go about caching the PDF? Has anyone any experience with this?
Srsly?
What do you do if your chef-server vm crashes and you need to provision new app servers to keep your main business running? ... exactly.
So either you have a redundant chef-server setup OR you'll get into trouble. It's just a matter of time.
Trading in a SPOF-less environment for convenience is a very, very bad DevOps guide.
if your using rvm, you can't just:
you need to state the gemset too, thus having an accepted .rvmrc that states the gemset is important.
seems to work also. if you don't then you get log messages that are along the lines of: "cannot load such file -- bundler/setup"
at least that was my experience with using the above version of ruby and rails.
also, the whenever gem would default to production. so if your running whenever in development you want to also state:
This is exactly the episode I was looking for. Ryan Bates is a leg-end!
One thing I'm not sure about:
Should there be a call to
rbenv rehash
inserted some where in one of the capistrano recipes. I tried adding paperclip to a project and deploying it but the application is not picking it up when it starts up. The recipe does run thebundle
command to install new gems when doing a standardcap deploy
but from what I can see from reading around I suspect therbenv rehash
needs to be called after thebundle
command and I'm not sure if it is included in the recipe provided by Ryan in this example. If this is the case it would explain why my app is not picking up paperclip and is not starting. I'm not sure myself where or how I would make the call torbenv rehash
in the capistrano recipe.Perhaps some would be kind enough to point me in the right direct?
Hi Ryan, I'd like to congratulate you for this wonderful job at railscasts.com. I'd love to see a screencast on how this Http caching techniques would play with something like Varnish cache or any other reverse-proxy/cache system.
Long live to railscasts!
Hi Ryan,
having issues testing my helpers using Test::Unit. It seems that when a helper method uses url_for (i.e. link_to) it doesn't call the modified url_for method in the UrlHelper module.
I've added
but that doesn't help.
Any hint?
I'm using acts-as-taggable-on and was wondering how I might go about creating a new tag if one wasn't found already. I've tried several things and I keep getting an error where its searching for a tag with an id of 0 whenever it doesn't know about the tag already
It doesn't have any generators, it uses the asset pipeline to add the assets into your asset load path.
How can I show validation errors?
Thanks Michael. I think I will use will_filter in my project. PDF's would be a handy feature to so thanks for looking it to it.
Thanks Ryan, have wanted to tune my logs a little more. Good jump off point.
@Milovan: I've had this (raw HTML) issue too. I thought it was being caused by Glimmer Blocker, but having removed Glimmer, the problem persists (on Safari, for me).
Create a file deploy.sh containing that command then all you have to do is run ./deploy.sh in future.
Thanks for great post.
How to integrate this when using cancan's load_resource instance?
Thanks for great post.
How to integrate this when using cancan's load_resource instance?
I'd like to use datatables but I'm using an api where not all columns are sortable and it has a weird way of passing the column argument, rather than column and direction i have to pass columnIsdesc=true or false or not pass it.
How would I go about that?
Thanks for this great railcast!
Is there a tutorial for how to let user drag and drop images into the mercury enabled editing space?
Thanks!
Pier.
I can confirm the issue with last seconds too.
Here is another bug (on Chrome at least). If you navigate away from this comments page (by entering url) and then press browser "Back" button, you'll see raw HTML.
Hello,
I want to ask a question that how can i upgrade bundler on production system? So i upgrade my bundler without problem from 1.0.10 to 1.1.0 as follows.
thats all and everyting fine for me.
Very nice tutorial. Thanks a lot.
At Rails 3.2.*,
I replace,
nifty_layout
->nifty:layout
nifty_scaffold
->nifty:scaffold
and concate nifty gem entry on Gemfile
also add line in
app/models/survey.rb
fileOne thing I noted when trying to implement datatables with server-side processing is that the SQL queries on search aren't as fuzzy as the default datatables search function. If you're going server-side, definitely check out other search solutions.
Ooooh sexy!
Very useful for my internal admin panels which use Bootstrap2.
Hi Ryan
Can you cover other features of data table in rails cast? features like add, delete, edit.
Hi guys, I have been trying to get everything mentioned in the video but for some reason I can't get my omniauth data stored in a session for when a new user registers. Everything else works, I can add an authentication to a user and sign in with it.
in authentications_controller.rb I have:
def create
...
end
in registrations_controller.rb I have
def build_resource(*args)
super
if session[:omniauth]
@user.apply_omniauth(session[:omniauth])
@user.valid?
session[:omniauth] = nil
end
end
In the terminal log I can see that the authentications for the user are getting built but once the user registers the authentication does not save and he has to add it again. What am I doing wrong? I can't figure it out!
Thanks in advance.
I got the same issue as Dignifiedquire on website watching, not iTunes podcast, last seconds are cuts off. Thanks Ryan for your excellent work.
Hi I'm wondering if anybody else ran into the problem with drawWinner()
I'm getting the error
Uncaught TypeError: Cannont call methoed 'drawWinner' of undefined.
I've gone back over the code above and copied and pasted it but still no luck. Any ideas?
Thanks
Linda
Ack, I knew I'd figure it out as soon as I posted a question. I needed to restart the server.
Not sure why this didn't work during
cap deploy
the first time, though.I followed this and am getting a 500 error complaining that
application.css
is not precompiled.I logged into the server and ran
rake assets:precompile
without issues, but running the app gives the same error again.Any ideas?
Ryan wrote this deploy.rb file with Ruby 1.9 syntax for hashes, and you appear to be using Ruby 1.8. I was also using Ruby 1.8. Here's how I fixed it:
At each place where it says "roles: :{role}", you need instead ":roles => :{role}".
The same is true for that "except: {no_release: true}" formulation, which needs you to add two hash arrows. It should become ":except => { :no_release => true }".
I was having the same problem and moving the require_tree means that the Raffler and Backbone not defined errors have gone. However the route is still not calling the Index function - so I don't see any alert on loading the page. Any ideas of where I can take it from here?
I was having the same problem as Cenature and moving the require_tree to the bottom of the page helped, and now I do not see any errors. However the index function is still not being called so I do not receive the alert 'home page' on loading the application. Anybody else with the same problem?
@Ryan 7:48 "We can cache these files like crazy"
to these u cant live without bootstrap: http://datatables.net/blog/Twitter_Bootstrap_2
Nice one! Thanks Ryan.
I just wrote a blog post on how you can include "running time" in your logs: http://zogash.tumblr.com/post/21138929607/running-time-in-rails-logs
the asset pipeline makes everything so easy /s
Why did it trigger an alert function when he clicked each entry (triggering "showEntry" and a new url opened?
Can someone kindly advise how I can resolve this error? I got this after installing the gemfile. I am new to rails and ruby. Appreciate it!
ExecJS::RuntimeError in Articles#index
Showing C:/Sites/dummy/app/views/layouts/application.html.erb where line #6 raised:
SyntaxError: octal escape sequences "\00" are not allowed on line 512
(in C:/Ruby193/lib/ruby/gems/1.9.1/gems/mercury-rails-0.3.1/vendor/assets/javascripts/mercury/regions/editable.js.coffee)
Sweet!