Btw, I modified the rails-i18n repository with many core translations you mentioned and made it a plugin. I found it a bit easier and more maintanable to simply update a plugin instead of copy&pasting the core translations into my own .yml files every time.
The plugin can be found at http://github.com/zargony/rails-i18n
Great Screencast, thanks Ryan.
I've been doing apps in multiple languages for quite some time now. I started with ruby-gettext about 2 years ago and just switched to Rails i18n in a recent app. It's really great to have an API for i18n included in Rails.
For those who are interested in i18n - I'm posting thoughts, ideas and experiences with Rails i18n to my blog from time to time.
Do you know if it's possible to create an attachment inside a controller?
I mean, I have some text stored in a string. I want to create an attachment that is a plain text file containing the contents of that string into a given model object.
Excellent tutorial! I have a problem regarding has_many and the dependent => :destroy command. I have two models, one for an Item and another for Variation but when I delete my item the variations connected to it isn't deleted, even though I have the :dependent => :destroy attribute set.
A short preview can be found at http://pastie.org/327247.
I can get my variations when I view the item, I can update and everything. It's just when I want to delete the Item. Any suggestions?
Made my way here from Tardate 11.1[1] ... all worked as advertised (Rails 2.2.2, restful_authentication and open_id_authentication plugins). There was some minor breakage in open_id_authentication and request.relative_url_root which Josh fixed in Sep 2008[2] but hasn't made its way into the default plugin install. Don't know why @George had a hard time with it; he didn't give much info to go on.
Thanks, Ryan, for the excellent screencasts. I have great admiration for you. ;]
--j
p.s. @Darryl (comment #4): Thanks for the link to http://webtypography.net ... an excellent site I didn't know about.
For anyone on OSX getting the ".../tmp/stream.3916.0 is not recognized by the 'identify' command" error, it's probably that identify is not in your path. The macport install and other installs do not always seem to get this right.
To fix:
* check if "identify" is in your path from the same terminal where you're about to run your "ruby server/script" command - just try to run it from the terminal prompt
* if it won't run, try entering these commands:
tom:~ tom$ export MAGICK_HOME="/opt/local/"
tom:~ tom$ export PATH="$MAGICK_HOME/bin:$PATH"
tom:~ tom$ export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib"
(you may have to adjust MAGICK_HOME to match your install)
After that, try running identify again from your RoR site's root dir. It should now work. If it does, run your server and see if your photos now work.
(You'll want to make sure the above PATH changes are made permanent if this fix does help.)
Heads up on a little gotcha that had us scratching our heads since last night.
It seems the js.erb file still generates the file within a layout, which went against my assumptions of the layout being left out, a la rjs.
So if you're getting loads of html returned and you're thinking along the lines of some sort of mime type confusion, have a closer look at what's coming back and stick a render :template => false in your format.js block.
Thank you for this post. I was trying to make this work, but unfortunately the code in the create.js.erb is not being executed. The text in the message form is stored in the database correctly and I assume that the create.js.erb file is found, as I get an error if I delete it. The problem is that the popup alert does not appear.
Please help!
I wrote a pretty extensive article about the whole topic of Memoization. Maybe this can be an additional source of information for some people: http://www.railway.at/articles/2008/09/20/a-guide-to-memoization (*shameless self-promotion*).
In my comment earlier (#38), i mistakenly wrote if there was a way to make the link_to :delete "less unobtrusive". What I obviously meant, was to make it "less obtrusive". Oh the vagaries...
Daniel, thanks for the pastie, i'd like to see how your structure your html in the pastie as well. I think you are relying on the fact that there is a edit link around the delete link. How about relying on the href of the delete link itself?
i18n screencast would be great. AFAIK internationalization in rails will be useful only for titles, headers, some short phrases, rubrics... that is it is for translating interface, not the content of the page. Would be nice if smbd share what he/she uses for fully localizing the app.
I just want to confirm that I was also having problems where, after setting up subdomain_fu the app seemed to think that 'www' was an account name and so through an error. I followed the advice of @bryce (#30 above) and simply changed:
:conditions => { :subdomain => /.+/ }
to
:conditions => { :subdomain => true }
This seems to be working fine - 'www.myapp.com' now defaults to the same place as 'myapp.com'
So, I think it should be made clear that the memoization feature of Rails only works -per- request, not over a span of multiple requests. Therefore, if you call the memoized function on one page, it will not be cached for the next page, or any future pages. This is really only useful if you have to call the same request over and over on a single page (read: partials), etc.
Also, keep in mind that Rails caches database requests automatically, so having a memoized method for anything relating to the database isn't really that useful.
I was able to play the video under Ubuntu 8.10 using mplayer as long as I didn't resize to full screen (video went blank if I did). and if I paused it when I hit play again it started over from the beginning.
Ubuntu Hardy, can't play either format in any of my 5 video players. Up to this one, the 'alternative download' played more reliably, but I get video without sound on this one (with all 5 players).
I just built mplayer from subversion, and it does exactly the same thing.
Guessing at the content of the video from the show notes is not going to work for me. I wonder if the Peepcode videos will also give me trouble? I guess it's time to pay up and see.
For those having problems with the video, I'm hoping to add another compression option (non QuickTime) soon. I just haven't been able to get around to it quite yet. Sorry for the inconvenience.
@MTH internationalization is definitely one of the major additions to 2.2, and I will be covering it sometime in this series. :)
Sorry, but the video cannot be played under Windows/Linux neither with latest VLC, nor MP with codecs? Any word on new compression format being used?
Thanks.
Hi Pat, there is one more issue,
sphinx is creating problem for rails polymorphic association
like
define_index do
indexes user.source.institution.name
end
it is not working for multiple source types,like if source types are Enterprise and Resource.and above condition is only for Resource.
is there any if condition while creating indexes like indexes user.source.institution.name if user.source_type == 'Resource'
Great screencast, I am not using jRails for the same reason you mentioned. Jeff, submit(handler) is a shorthand for using bind('submit', handler). Take a look at the "Events" section found here: http://jquery.bassistance.de/api-browser
Yves i'm nearly sure I've done that in the past with attachment_fu. I wanted to use the mp3-info library to extract data from a sound file upload even if the upload failed in validations.
You can use a before_save method in the model to access the file (using self.temp_path) before it has been saved. You can then do anything you want with it.
Or you could write your own validations, or modify the existing ones.
Btw, I modified the rails-i18n repository with many core translations you mentioned and made it a plugin. I found it a bit easier and more maintanable to simply update a plugin instead of copy&pasting the core translations into my own .yml files every time.
The plugin can be found at http://github.com/zargony/rails-i18n
Wookie wookie ^^ ...
or in other words ^^ ... just great.
Great Screencast, thanks Ryan.
I've been doing apps in multiple languages for quite some time now. I started with ruby-gettext about 2 years ago and just switched to Rails i18n in a recent app. It's really great to have an API for i18n included in Rails.
For those who are interested in i18n - I'm posting thoughts, ideas and experiences with Rails i18n to my blog from time to time.
Nice Screencast!
All we need now is a good way to do model translation... :)
Yeah, that's what I need!
And now I can remove Globalite for sure 8-)
Thanks, Ryan!
Hi guys,
Any idea how to use 'debugger' with this type of setup in development?
Many thanks for another useful screencast.
:)
Hello Ryan,
Do you know if it's possible to create an attachment inside a controller?
I mean, I have some text stored in a string. I want to create an attachment that is a plain text file containing the contents of that string into a given model object.
Is this possible?
Thanks!
Hi Ryan,
Excellent tutorial! I have a problem regarding has_many and the dependent => :destroy command. I have two models, one for an Item and another for Variation but when I delete my item the variations connected to it isn't deleted, even though I have the :dependent => :destroy attribute set.
A short preview can be found at http://pastie.org/327247.
I can get my variations when I view the item, I can update and everything. It's just when I want to delete the Item. Any suggestions?
Kind regards,
Niklas
Made my way here from Tardate 11.1[1] ... all worked as advertised (Rails 2.2.2, restful_authentication and open_id_authentication plugins). There was some minor breakage in open_id_authentication and request.relative_url_root which Josh fixed in Sep 2008[2] but hasn't made its way into the default plugin install. Don't know why @George had a hard time with it; he didn't give much info to go on.
Thanks, Ryan, for the excellent screencasts. I have great admiration for you. ;]
--j
p.s. @Darryl (comment #4): Thanks for the link to http://webtypography.net ... an excellent site I didn't know about.
[1] http://tardate.blogspot.com/2008/10/restfulauthentication-and-openid-with.html
[2] http://github.com/rails/open_id_authentication/commit/00d8bc7f97b9a3113e004475b63dbf84f5397237
memoize :what_are_we_eating
Great tutorial, Ryan. Many thanks. I used Olli's suggestion (comment #23) to make the checkboxes' IDs W3C-compliant.
Keep up the good work!
-Nick
Does memoize :find_by_id work too?
For anyone on OSX getting the ".../tmp/stream.3916.0 is not recognized by the 'identify' command" error, it's probably that identify is not in your path. The macport install and other installs do not always seem to get this right.
To fix:
* check if "identify" is in your path from the same terminal where you're about to run your "ruby server/script" command - just try to run it from the terminal prompt
* if it won't run, try entering these commands:
tom:~ tom$ export MAGICK_HOME="/opt/local/"
tom:~ tom$ export PATH="$MAGICK_HOME/bin:$PATH"
tom:~ tom$ export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib"
(you may have to adjust MAGICK_HOME to match your install)
After that, try running identify again from your RoR site's root dir. It should now work. If it does, run your server and see if your photos now work.
(You'll want to make sure the above PATH changes are made permanent if this fix does help.)
Heads up on a little gotcha that had us scratching our heads since last night.
It seems the js.erb file still generates the file within a layout, which went against my assumptions of the layout being left out, a la rjs.
So if you're getting loads of html returned and you're thinking along the lines of some sort of mime type confusion, have a closer look at what's coming back and stick a render :template => false in your format.js block.
Cheers,
Jon
Thank you for this post. I was trying to make this work, but unfortunately the code in the create.js.erb is not being executed. The text in the message form is stored in the database correctly and I assume that the create.js.erb file is found, as I get an error if I delete it. The problem is that the popup alert does not appear.
Please help!
This broke for me when upgrading to 4 5 kiralık satılık emlak gayrimenkul
Thanks Ryan,I think this is one of the most wonderful sites. I have great admiration for you.Gayrimenkul degerleme ekspertiz
I don't think you are supposed to ignore the Manifest file on github.
I have tested the video on my XX too and as expected it work like charm.
On my Ubuntu the Totem Movie Player(gstreamer) and on XP the QuickTime player without any problem can play this movie.
To repeat my self in this DRY community: The movie is working fine.
:-)
Great cast Ryan,
I would like to know what you think of this approach:
http://www.ghostonthird.com/2007/11/25/a-rails-form-that-creates-multiple-models-at-once/
Its a little different than yours and I trying to figure out the advantages/disadvantages of using one or the other.
It seems that this doesn't work for Rails 2.2+ yet. Eric hasn't gotten around to fixing it, either. Any ideas, Ryan?
http://clearspace.seleniumhq.org/thread/15609
Just revisting / redownloading this again.
It really should be titled "Crackers ..." .. not "Hackers ..." ;)
Mike
Wonderful stuff, had no idea it had been released until I stopped by here!
Thanks!
Really so great, a serie of screencast on Rails 2.2. :)
I wrote a pretty extensive article about the whole topic of Memoization. Maybe this can be an additional source of information for some people: http://www.railway.at/articles/2008/09/20/a-guide-to-memoization (*shameless self-promotion*).
In my comment earlier (#38), i mistakenly wrote if there was a way to make the link_to :delete "less unobtrusive". What I obviously meant, was to make it "less obtrusive". Oh the vagaries...
Daniel, thanks for the pastie, i'd like to see how your structure your html in the pastie as well. I think you are relying on the fact that there is a edit link around the delete link. How about relying on the href of the delete link itself?
Hi Faisal
It should work, if there's existing records for both Enterprise and Resource instances tied to your user model.
TS needs existing records to figure out what to join on.
Might be best to continue this discussion on the google group:
http://groups.google.com/group/thinking-sphinx
i18n screencast would be great. AFAIK internationalization in rails will be useful only for titles, headers, some short phrases, rubrics... that is it is for translating interface, not the content of the page. Would be nice if smbd share what he/she uses for fully localizing the app.
I just want to confirm that I was also having problems where, after setting up subdomain_fu the app seemed to think that 'www' was an account name and so through an error. I followed the advice of @bryce (#30 above) and simply changed:
:conditions => { :subdomain => /.+/ }
to
:conditions => { :subdomain => true }
This seems to be working fine - 'www.myapp.com' now defaults to the same place as 'myapp.com'
You're my GOD Ryan ! :)
i18n screencast in the near future, great ! ;)
Short, sweet, and as always - uber useful.
Thanks Ryan.
So, I think it should be made clear that the memoization feature of Rails only works -per- request, not over a span of multiple requests. Therefore, if you call the memoized function on one page, it will not be cached for the next page, or any future pages. This is really only useful if you have to call the same request over and over on a single page (read: partials), etc.
Also, keep in mind that Rails caches database requests automatically, so having a memoized method for anything relating to the database isn't really that useful.
Hope this helps someone! :) Thanks, Ryan.
I was able to play the video under Ubuntu 8.10 using mplayer as long as I didn't resize to full screen (video went blank if I did). and if I paused it when I hit play again it started over from the beginning.
EnvyCasts.com has a great video on Rails 2.2 features.
Ubuntu Hardy, can't play either format in any of my 5 video players. Up to this one, the 'alternative download' played more reliably, but I get video without sound on this one (with all 5 players).
I just built mplayer from subversion, and it does exactly the same thing.
Guessing at the content of the video from the show notes is not going to work for me. I wonder if the Peepcode videos will also give me trouble? I guess it's time to pay up and see.
For those having problems with the video, I'm hoping to add another compression option (non QuickTime) soon. I just haven't been able to get around to it quite yet. Sorry for the inconvenience.
@MTH internationalization is definitely one of the major additions to 2.2, and I will be covering it sometime in this series. :)
another useful screencast, thanks Ryan! :)
After upgrading to Rails 2.2.2 from a 2.0.2 version I had to remove the following setting from my environment file (development.rb)
config.action_view.cache_template_extensions
The cache_template_extension has been deprecated in ActionView with the latest RoR release, so my server wouldnt startup properly.
Regards
I'm using opensuse/gnome and can't watch the video in the browser. I must download and open with MPlayer.
Other .mov videos are shown well from other sites ...
Please, continue on railscasts about new features.
Especially *internalization*.
Thanks!
This description really helped me a lot. Thanks. ;)
Dejan Dimic, you have to make sure your ubuntu can play restricted media. Google around on how to play media files.
Video works fine as always. Currently on my Ubuntu but I expect the same on my Xp. Nevertheless, I'll test it.
The subject is on the spot as we all tend to forget the little things that can easily speed up our application.
@jc Thank you for this very interesting explanation. This may be a good alternative to the FileUtils.
Sorry, but the video cannot be played under Windows/Linux neither with latest VLC, nor MP with codecs? Any word on new compression format being used?
Thanks.
Hi Pat, there is one more issue,
sphinx is creating problem for rails polymorphic association
like
define_index do
indexes user.source.institution.name
end
it is not working for multiple source types,like if source types are Enterprise and Resource.and above condition is only for Resource.
is there any if condition while creating indexes like indexes user.source.institution.name if user.source_type == 'Resource'
So how can i handle this.
Great screencast, I am not using jRails for the same reason you mentioned. Jeff, submit(handler) is a shorthand for using bind('submit', handler). Take a look at the "Events" section found here: http://jquery.bassistance.de/api-browser
I'm a grateful student of all of this. Please forgive me if I'm wrong, but shouldn't the submitWithAjax portion in application.js read:
this.submit= function() {
and not
this.submit(function() {
?
Isn't the idea to redefine the submit function?
Thanks for your efforts, I've learned alot from them.
Yves i'm nearly sure I've done that in the past with attachment_fu. I wanted to use the mp3-info library to extract data from a sound file upload even if the upload failed in validations.
You can use a before_save method in the model to access the file (using self.temp_path) before it has been saved. You can then do anything you want with it.
Or you could write your own validations, or modify the existing ones.