It's worth noting that Rails 3 beta2 has a problem with latest Ruby 1.8.7 and with Ruby 1.9.1. The release notes for Rails 3 beta2 says:
"Note that Ruby 1.8.7 p248 and p249 has marshaling bugs that crash both Rails 2.3.x and Rails 3.0.0. Ruby 1.9.1 outright segfaults on Rails 3.0.0, so if you want to use Rails 3 with 1.9.x, jump on 1.9.2 trunk for smooth sailing."
Thanks again for this great work.
It appears the link to the http_authentication.rb source shown above is no longer valid since the code moved to github.
Nice screncast, as usual :-) But one recommendation would be, instead of re-parsing the code snippet at every request and caching it in the view, it is better to add the parsing as a before_save hook in the model and store the final HTML already pre-rendered in another text column in your table. Then the view has only to display this column instead of the original and because of this, it won't matter which library is faster because you only have to run it once and not at every request.
Hey Ryan,
Thanks for the informative screencast. Looking at the benchmarks, I was wondering how much of Pygments slow performance is from shelling and how much is due to Pygments itself.
I'm not very familiar with this benchmarking stuff though (the next Railscast?:-). On my machine coderay is about the same, 0.24 total and pygmentize is 9.28.
Not to discredit Pygments, I wrote up the following snippet, which may not be that useful for Rails developers. It returns 0.496517 usec to run Pygments 50 times from Python. Not sure exactly how to get more consistent benchmarks between the two.
Here's something I found on making a sorted, nested list:
http://www.justinball.com/2009/01/18/heirarchies-trees-jquery-prototype-scriptaculous-and-acts_as_nested_set/
via
http://stackoverflow.com/questions/198047
It uses
http://github.com/collectiveidea/awesome_nested_set
but it seems sorta complicated. Got any simpler solutions?
I was wondering if there were any reasons you chose the ruby-based libraries over javascript libraries, other than the rails-specific target of the screen-cast series?
@Matt, using Rack middleware is an interesting solution for this. I haven't looked into it but does performance become a problem? I imagine it needs to look through every HTML page even if there is no <pre> block on it, and is it possible to cache the results?
@hakunin, thanks for the notes and very good points. I always forget the syntax for non matching parenthesis.
@grigio, I'm not very familiar with these editors, but you just need to determine what they generate for the code syntax and swap that out like I do with the <code> tag in this episode.
@Memiux, I'm experimenting with other video codecs because, unfortunately, the Animation codec which I normally use is very buggy in Snow Leopard. I hope to find a solution which is nearly as good quality as Animation.
1) In the regexp, if you are not going to be using a matching group, you can mark it as a non-matching group using '?:', ie /(?:this_group_wont_match)/, so you can use $2, $1, instead of $3, and $2. In your case it would look like this: /\<code(?: lang="(.+?)")?\>(.+?)\<\/code\>/m.
2) Changing code tag into div may not be a good idea if you're planning to have both inline and block code. code tag is by itself an inline element. To use block code it may be better to wrap code in pre.
Nice screencast, as always.
If I remember correctly using TMail in 2.3 we can also just call create_mailer_method to get the TMail object and call deliver on it.
The dynamic methods of 2.3 with "deliver_mailer_method" are just fine with me.
But thanks for pointing out to move the sending of registration Emails out of the Observer into the controller. That's indeed a good point.
Other than that with 2.3 Mailer we can already compose multipart message with views, I fail to see the real difference on the surface. Maybe a lot has changed under the hood.
Do you know if there is a way to override the location of where the gems:unpack will go rather than having them go under vendor/gems? This is a case where multiple rails applications use the same version of a gem and we want to only store one copy of it in source control. Also is there a way to tell rake to look in a directory for gems and when you run gems:unpack so they are grabbed from the shared directory? Thanks in advance.
Thanks Ryan. I was having a problem -- wanted to have a drop-down menu (to select a Person to edit) and a button that said "Jump" to take you there -- and had just discovered that Rails couldn't generate the form html without knowing the id of the Person. Got a RoutingError instead.
I had been wondering whether a dispatcher-style redirect action would be a "nice" solution to this. Thanks for explaining it here.
Hey Ryan, Thanks for the tutorial. It would be awesome if i can get it so work tho... Whenever i type questions for a new survey and hit 'submit' the questions never get to the database.. . I'm running rails 2.3.5 on windows xp64 and Ruby 1.8.7.
The surveys are getting through just not the questions.
I'm having the same problem as @Till, inspite of having the size given as 392x306# it is cropping image of size 392x392, which is something very weird, and help needed from the experts regarding this, I'm staring at the issue for quite sometime with no solution.
But I have a question for anyone... I implemented the dynamic select menus just fine. But I want my final select to populate a "description" field that is not editable. Anyone know how to do that?
This is of minor use, but I found myself needing groups of roles. Here is my User model which includes several suggestions (@Marc-Andre Lafortune, @Matt Werner, and @琳琳的小狗 above.)
http://pastie.org/883113
The basic idea is to prefix role names with groups (employee_admin, employee_manager), add a hash of masks, and an associated function.
Thanks Ryan for CanCan and the weekly work on the RailsCast.
@Sigi: "All it does is introduce a different kind of coupling, one which is much harder to see than going to a join model and roles table: the precise number that contains the bitmask is COMPLETELY coupled with the array entries inside the ROLES constant."
The coupling of concern came from declarative authorization, where the roles which are in the database are now embedded in the Ability model. Install the app somewhere else and that will break unless the db contents are duplicated. By moving the roles into the user model, the code is not referring to the contents of the database and the coupling is removed.
The roles of a given user (and what is stored) are *always* going to be related to the list of available roles. This is not coupling. This will be the case no matter how you do authorization.
When you say you can call "deliver" later on the email...can you provide an example of this? I would be very interested in asynchronous email delivery in Rails 3. Looks like it is getting closer but would like to learn more.
@iain, using "join" is probably the best way so it is system independent. Thanks for pointing that out!
@Dave, I'm aware of the Snow Leopard problem, it's a bug with Animation codec in QuickTime. I'm hoping they fix it soon. You may want to use the iPod version in the meantime.
I don't use any syntax highlighting in Terminal. It's just a standard white on black theme.
I've been hedging on when to bite the Rails 3.0 bullet, but this tipped the scales.
Two things: I've noticed a problem with the video playback in Snow Leopard QT. The screen won't refresh unless you're moving the mouse or a lot of screen elements have changed. This even happens on the older casts. Try watching the intro all the way through, for instance, and you begin talking but the screen hasn't changed. Pausing and restarting causes the screen to update. I've noticed this on upgraded OSX as well as factory installs OSX.
Second, what are you using for syntax coloring in Terminal? Do you get it free from bash? I know you mentioned it in a cast a while back but I can't remember where. Maybe you could add your development environment to the About page.
Nice casts. If you are on Mac, you can use MockSMTP (http://mocksmtpapp.com) to test your mailer model.
It's a native mac application that mocks SMTP and display them in a nice GUI that looks like a mail reader. It supports multi-part mails and attachements.
This weekend I was just looking for infos about the new Action Mailer. Your sense of providing a screencast of exactly the thing I'm looking for is fantastic! great work!
It's worth noting that Rails 3 beta2 has a problem with latest Ruby 1.8.7 and with Ruby 1.9.1. The release notes for Rails 3 beta2 says:
"Note that Ruby 1.8.7 p248 and p249 has marshaling bugs that crash both Rails 2.3.x and Rails 3.0.0. Ruby 1.9.1 outright segfaults on Rails 3.0.0, so if you want to use Rails 3 with 1.9.x, jump on 1.9.2 trunk for smooth sailing."
You are the reason why I get out of bed on Monday mornings :-)
Thanks for another fantastic episode.
How does this work with HAML??
Thanks again for this great work.
It appears the link to the http_authentication.rb source shown above is no longer valid since the code moved to github.
when I use this method on localhost, everything works fine.. but, when I host it online, the application root directory is in domain.com/local
otherwise someone would have said something...
@Oskar Lissheim-Boethius, I use Safari and always get the HTTP box to input my details
Great screencast, really great!!! The comments also are very useful.
Thanks guys.
Nice screncast, as usual :-) But one recommendation would be, instead of re-parsing the code snippet at every request and caching it in the view, it is better to add the parsing as a before_save hook in the model and store the final HTML already pre-rendered in another text column in your table. Then the view has only to display this column instead of the original and because of this, it won't matter which library is faster because you only have to run it once and not at every request.
Is there an update on the pygments yet? Would also like to know this info.
on asp generated page, the form submit automatically fill 2 form variables:
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
before submit. How to define them in Mechanize? thx!
additional info: http://www.xefteri.com/articles/show.cfm?id=18
Hey Ryan,
Thanks for the informative screencast. Looking at the benchmarks, I was wondering how much of Pygments slow performance is from shelling and how much is due to Pygments itself.
I'm not very familiar with this benchmarking stuff though (the next Railscast?:-). On my machine coderay is about the same, 0.24 total and pygmentize is 9.28.
Not to discredit Pygments, I wrote up the following snippet, which may not be that useful for Rails developers. It returns 0.496517 usec to run Pygments 50 times from Python. Not sure exactly how to get more consistent benchmarks between the two.
http://gist.github.com/349504
Here's something I found on making a sorted, nested list:
http://www.justinball.com/2009/01/18/heirarchies-trees-jquery-prototype-scriptaculous-and-acts_as_nested_set/
via
http://stackoverflow.com/questions/198047
It uses
http://github.com/collectiveidea/awesome_nested_set
but it seems sorta complicated. Got any simpler solutions?
I was wondering if there were any reasons you chose the ruby-based libraries over javascript libraries, other than the rails-specific target of the screen-cast series?
I'm building a simple TODO list application and used this great tutorial to make my TODO list sortable. Thanks, Ryan! It worked! :)
Now, how do I make my TODO list also be nested? i.e. How do I use acts_as_list and acts_as_nested_set together (or is there a better way to do this)?
Thanks!
Ryan, thanks for another good tutorial.
It's seem a good step for highlight search result, am I right?!
I thought the method looks similar.
Does anyone know if there's a way to include values from multiple models in a single collection_select?
Thanks!
@Matt, using Rack middleware is an interesting solution for this. I haven't looked into it but does performance become a problem? I imagine it needs to look through every HTML page even if there is no <pre> block on it, and is it possible to cache the results?
@hakunin, thanks for the notes and very good points. I always forget the syntax for non matching parenthesis.
@grigio, I'm not very familiar with these editors, but you just need to determine what they generate for the code syntax and swap that out like I do with the <code> tag in this episode.
@Memiux, I'm experimenting with other video codecs because, unfortunately, the Animation codec which I normally use is very buggy in Snow Leopard. I hope to find a solution which is nearly as good quality as Animation.
Does it also work with FCKEditor or another WYSIWYG editor?
A couple of notes.
1) In the regexp, if you are not going to be using a matching group, you can mark it as a non-matching group using '?:', ie /(?:this_group_wont_match)/, so you can use $2, $1, instead of $3, and $2. In your case it would look like this: /\<code(?: lang="(.+?)")?\>(.+?)\<\/code\>/m.
2) Changing code tag into div may not be a good idea if you're planning to have both inline and block code. code tag is by itself an inline element. To use block code it may be better to wrap code in pre.
Thanks!
Another method (via vim):
http://gist.github.com/347644
It script save code highlight to html file in current dir.
I'm getting the exact same problems. Ryan should look into this and maybe suggest a possible solution.
@Steve Byrne: i had to use the following to install openssl lib on ubuntu:
rvm package install openssl
Nice screencast, as always.
If I remember correctly using TMail in 2.3 we can also just call create_mailer_method to get the TMail object and call deliver on it.
The dynamic methods of 2.3 with "deliver_mailer_method" are just fine with me.
But thanks for pointing out to move the sending of registration Emails out of the Observer into the controller. That's indeed a good point.
Other than that with 2.3 Mailer we can already compose multipart message with views, I fail to see the real difference on the surface. Maybe a lot has changed under the hood.
Ryan,
Do you know if there is a way to override the location of where the gems:unpack will go rather than having them go under vendor/gems? This is a case where multiple rails applications use the same version of a gem and we want to only store one copy of it in source control. Also is there a way to tell rake to look in a directory for gems and when you run gems:unpack so they are grabbed from the shared directory? Thanks in advance.
Thanks Ryan. I was having a problem -- wanted to have a drop-down menu (to select a Person to edit) and a button that said "Jump" to take you there -- and had just discovered that Rails couldn't generate the form html without knowing the id of the Person. Got a RoutingError instead.
I had been wondering whether a dispatcher-style redirect action would be a "nice" solution to this. Thanks for explaining it here.
Great, thanks!
Regression testing is about proving that the modified/new code does not impact on the existing code - which is what you are hinting at above.
What I'm missing is how to include an image inside the email.
text
img
more text.
Also, I get "Net::SMTPAuthenticationError: 530 5.7.0 Must issue a STARTTLS command first" errors when using the gmail stuff. Any ideas?
Very useful, Ryan. Thanks!
Now that I've built my surveys, how do the users answer them?? Does anyone have sample controllers/views for implementing the user interface?
Hey Ryan, Thanks for the tutorial. It would be awesome if i can get it so work tho... Whenever i type questions for a new survey and hit 'submit' the questions never get to the database.. . I'm running rails 2.3.5 on windows xp64 and Ruby 1.8.7.
The surveys are getting through just not the questions.
Any ideas on why that might be?
Thanks for the example!
I'm having the same problem as @Till, inspite of having the size given as 392x306# it is cropping image of size 392x392, which is something very weird, and help needed from the experts regarding this, I'm staring at the issue for quite sometime with no solution.
Thanks in advance
Great, but what about Aegis?
http://github.com/makandra/aegis
It seems to have put all the pieces together in a very practical way also...
I think I'm in love with Ryan. ;)
But I have a question for anyone... I implemented the dynamic select menus just fine. But I want my final select to populate a "description" field that is not editable. Anyone know how to do that?
Thanks!
This is of minor use, but I found myself needing groups of roles. Here is my User model which includes several suggestions (@Marc-Andre Lafortune, @Matt Werner, and @琳琳的小狗 above.)
http://pastie.org/883113
The basic idea is to prefix role names with groups (employee_admin, employee_manager), add a hash of masks, and an associated function.
Thanks Ryan for CanCan and the weekly work on the RailsCast.
@Sigi: "All it does is introduce a different kind of coupling, one which is much harder to see than going to a join model and roles table: the precise number that contains the bitmask is COMPLETELY coupled with the array entries inside the ROLES constant."
The coupling of concern came from declarative authorization, where the roles which are in the database are now embedded in the Ability model. Install the app somewhere else and that will break unless the db contents are duplicated. By moving the roles into the user model, the code is not referring to the contents of the database and the coupling is removed.
The roles of a given user (and what is stored) are *always* going to be related to the list of available roles. This is not coupling. This will be the case no matter how you do authorization.
When you say you can call "deliver" later on the email...can you provide an example of this? I would be very interested in asynchronous email delivery in Rails 3. Looks like it is getting closer but would like to learn more.
This episode was great!
This description really helped me a lot. Thanks
Thanks for the tip about interceptors, Ryan! That's going to prove very useful, I'm sure.
Keep up the phenomenal work!
Rails make programming getting easy and simple. I think every web programming will use it... if they knew.
Thanks for Another casts Ryan.
@iain, using "join" is probably the best way so it is system independent. Thanks for pointing that out!
@Dave, I'm aware of the Snow Leopard problem, it's a bug with Animation codec in QuickTime. I'm hoping they fix it soon. You may want to use the iPod version in the meantime.
I don't use any syntax highlighting in Terminal. It's just a standard white on black theme.
Amazing railscast Ryan, thanks!
I'm finding a method to unit/functional testing outgoing emails like MockSMTP.app. But I'm using Linux to development. Have you got any idea? Thanks!
I've been hedging on when to bite the Rails 3.0 bullet, but this tipped the scales.
Two things: I've noticed a problem with the video playback in Snow Leopard QT. The screen won't refresh unless you're moving the mouse or a lot of screen elements have changed. This even happens on the older casts. Try watching the intro all the way through, for instance, and you begin talking but the screen hasn't changed. Pausing and restarting causes the screen to update. I've noticed this on upgraded OSX as well as factory installs OSX.
Second, what are you using for syntax coloring in Terminal? Do you get it free from bash? I know you mentioned it in a cast a while back but I can't remember where. Maybe you could add your development environment to the About page.
Amazing as usual mate... Can't wait for Rail 3.0 to be out of Beta and using it in live applications...
Plus new version ActionMailer API developer is Aussie... Wahoooooo!
Thank you for your answer Trek Glowacki.
But unfortunately i'm not using Amazon S3... The photos are stored on the local server..
i think the photos are in the right ratio, but the file-dimensions are calculated wrong.. so, avatar_gemoetry seems to work
File attach, different views!
I am happy!
Nice screencast, once again!
Shouldn't:
File.read("#{Rails.root}/public/images/rails.png")
be:
File.read(Rails.root.join('public', 'images', 'rails.png'))
Much nicer IMHO.
Nice casts. If you are on Mac, you can use MockSMTP (http://mocksmtpapp.com) to test your mailer model.
It's a native mac application that mocks SMTP and display them in a nice GUI that looks like a mail reader. It supports multi-part mails and attachements.
This weekend I was just looking for infos about the new Action Mailer. Your sense of providing a screencast of exactly the thing I'm looking for is fantastic! great work!
Hi
How can I determine if a job is finished ?