I know it sounds a bit purist, but using virtual attributes this way you're tightening your model with the view, aren't you?
Besides that, how can I pass two or more parameters in the ajax request with the :param_name option? I got it working with the :with option, but that is a bit ugly.
This tutorial just saved me even MORE time. I was missing the def to_param in the user model. I was about to start messing with the routes, thankfully this is a much cleaner way to get this done.
Some of these things should be easier done. Oh well. Thank you!
@Alex, you can still do that, you'll just have to use the full timestamp as the specified version. What I usually do is run "rake db:rollback" as many times as needed.
@Don, thanks, fixed. :)
@sthapit, while I haven't fully tested this, I believe everything will just work. You don't have to rename anything, it will just use the existing version numbers. Also when you first run the migration I'm assuming it will properly generate the schema_migrations table and fill it will the existing entries. Someone please correct me if I'm wrong.
if i update rails to 2.1 and then run migrations on an existing project in 2.0 does this mean that i would have to rename all my db/migrate files? and since my migrations have already been run in my 2.0 project, the schema_migrations (which don't exist yet) also don't have the proper entries for tables that already exist... is there a rake task that will ready an existing rails 2.0 project to co-exist with 2.1 migrations?
Hi Ryan! Great lesson! It has been helping me a lot on this project on school records (or so I hope it will). However, I'm stuck in this one part.
See, I'm using collection_select or a drop down list dealing with an object instead of just text_fields, and I'm stumped as to where to put the array in the parameters, or how to put it.
Ryan, I really like this technique. I too have some concerns about performance, but for now this has already opened my eyes to many things that ruby & rails are capable of.
I am wondering though, how would you write specs for something like this? I am guessing they would be unit tests rather than helper tests? Do you have to do anything special to set them up?
Thanks again Ryan. I've turned to your site a primary source of learning rails ideas (and rails in general).
Have you (would you) consider posting the projects you use in the screen casts on your site?
I know there are many times, I would love to be able to peer through the code itself (in the event I missed you explaining something previously).
@Eric, I would like to see more support for international users as well. Please do consider submitting a ticket/patch on this.
@David, this is actually generated by the TimeZone#to_s method, so you can override that if you want something different. That feels a bit hackish, so alternatively you can subclass TimeZone and pass that to the select field. I'm not sure if this will work though:
http://pastie.caboo.se/196823
Why exactly are you so worked up over this issue? There are rake tasks for all timezones and one that guesses your local timezone based on your system time.
While I agree having some degree of internationalization would be nice Rails has many other instances where specific internationalization support is not offered. The timezone Internationalization issue isn't really out of line with the existing core development philosophy.
I feel very bad when I see such shortcut : #us_zones. US is not the center of the world.
Do we still think that US is more important than other countries ? Why not #russia_zones or #china_zones ? or at least #euro_zones ? or if we really want to be america centric why not #canada_zones ?
We shouldn't have such shortcut in the core, we should *never* have US be a prioritized value or even a default value. This is very bad practice.
Worse, we have a #us_zones and we don't even have a #utc_timezone or #gmt_timezone shortcut.
i love your railscasts. i'm sure it helps pushing rails a lot.
my question:
is there a way to get ActiveResource objects when using custom methods like get instead of hash/array of hashes?
Yes, I am using submodules to track all plugins where possible. I like that it keeps a list of everything managed by git in a single .gitmodules file at the root of your main project.
Has anyone else noticed anything odd about the sound in some of these episodes (for example this one)? I'm using Quicktime on Windows and at 5:47 seconds there is a small cutout in the sound, and if you look at the timer in the lower left hand corner it stops updating for about 2 seconds and skips to 5:50. There are a couple of other points where it does the same thing, and I've heard in it a few other railscasts, and I'm wondering if it is just my system, can anyone else verify this?
nice screencast (as always). Is there any chance you could clarify the repercussions of cloning an external git repository (as you suggest) inside a project which itself is already managed by git.?
So far I have been using braid (http://github.com/evilchelu/braid/tree/master) to pull in external git repositories (which I think links to the repositories as a submodule in a separate branch). This is mainly because I assumed there might be issues with storing git repositories within git repositories. However, I may be wrong...
Anway, suffice to say, a lot of this git stuff is still new to me, and probably a lot of other people too :-)
Try removing any other versions of Ruby apart from the one that ships with OS X 10.5. (The MacPorts install of Ruby was occasionally causing this conflict after I upgraded.)
Nice episode as always :) I have watched all your episode and as a result I have learned a whole lot about how to develop Rails applications. I have been trying these past days to find a good tutorial on how to upload files, images to be exact :). Is it possible you could do an episode on how to do this in Rails 2.1 in the near future? I have done a little experimenting with Django and uploading images there is very simple. I have followed a few Rails examples on this but they seem out-dated and "hackish". Sorry about the long comment, keep up the excellent work. I look forward to a new episode every Monday 8-)
Thanks for the answers. Glad I asked. I'm trying to get started with Rails (working through Agile...) and hard to figure out how all the Rails and Ruby pieces fit together particularly since so many new pieces being developed: Merb, Rubinus, Passenger, Rack, Mongrel, RSpec, Mephisto etc. Trying to figure out what I need to pay attention to and what I don't.
@Fred, that should work too, and I should have mentioned it. I just prefer to update an individual project through the vendor directory so I don't unintentionally update another project. At least until the final 2.1 is released.
First, I'm not certain that the RC is available as a gem yet.
Even is if is, there are a couple reasons this might be better.
1. You don't want to upgrade every app running on your machine before you've had a chance to check out how the new framework will affect your code. So installing Rails into the vendor directory is a little "safer" in that it breaks one app instead of all of your apps.
2. A lot of rubyists are on shared hosts and can't run "sudo gem install" anything.
I know it sounds a bit purist, but using virtual attributes this way you're tightening your model with the view, aren't you?
Besides that, how can I pass two or more parameters in the ajax request with the :param_name option? I got it working with the :with option, but that is a bit ugly.
Ryan, could you show the view that is calling this template?
The scaffold generator in Rails 2.0 may be setting things up differently, but I'd like to see your render :partial call to be sure.
This tutorial just saved me even MORE time. I was missing the def to_param in the user model. I was about to start messing with the routes, thankfully this is a much cleaner way to get this done.
Some of these things should be easier done. Oh well. Thank you!
@Alex, you can still do that, you'll just have to use the full timestamp as the specified version. What I usually do is run "rake db:rollback" as many times as needed.
@Don, thanks, fixed. :)
@sthapit, while I haven't fully tested this, I believe everything will just work. You don't have to rename anything, it will just use the existing version numbers. Also when you first run the migration I'm assuming it will properly generate the schema_migrations table and fill it will the existing entries. Someone please correct me if I'm wrong.
if i update rails to 2.1 and then run migrations on an existing project in 2.0 does this mean that i would have to rename all my db/migrate files? and since my migrations have already been run in my 2.0 project, the schema_migrations (which don't exist yet) also don't have the proper entries for tables that already exist... is there a rake task that will ready an existing rails 2.0 project to co-exist with 2.1 migrations?
Where version number? I kid, the grammar nazi attacks. I think that is "their version number"
Hi Ryan! Great lesson! It has been helping me a lot on this project on school records (or so I hope it will). However, I'm stuck in this one part.
See, I'm using collection_select or a drop down list dealing with an object instead of just text_fields, and I'm stumped as to where to put the array in the parameters, or how to put it.
Care to enlighten me?
eg.
collection_select("enlist_subject", "subject_id", Subject.find(:all), :id, :title)
which can also be written/written originally as:
collection_select(:enlist_subject, :subject_id, Subject.find(:all), :id, :title)
*I don't think this will need the <% fields_for ... %> part anymore.
Hope you or anyone can help. Thanks!!
What if I want to rollback some migrations?Let's say I have
create_users
create_products
create_categories
and I want to roll back until the product migration.Before this changeset,I could easily do this by typing rake db:migrate VERSION=X
Congrats from me too. 100 screen casts and I watched almost every single one of them! Thanks a lot! Keep up the good work!
I was aware of the changes going up and down with the version but not of this. Nice screencast, as always :)
Keep it up
Quoting one of my favorite simpsons episodes:
"Dear die hard...you rock! P.S. Do you know mad max?"
Seriously...you rock.
Hi, Im getting this error when running script/generate exception_migration
Does anyone have an idea of what's going on?
/vendor/plugins/exception_logger/init.rb:3:in `load_plugin': undefined method `view_paths=' for LoggedExceptionsController:Class (NoMethodError)
@Matt, I'm just starting to do this actually. You can find the code here:
http://github.com/ryanb/railscasts-episodes/
what does the :db in to_s(:db) do?
Ryan, I really like this technique. I too have some concerns about performance, but for now this has already opened my eyes to many things that ruby & rails are capable of.
I am wondering though, how would you write specs for something like this? I am guessing they would be unit tests rather than helper tests? Do you have to do anything special to set them up?
Thanks again Ryan. I've turned to your site a primary source of learning rails ideas (and rails in general).
Have you (would you) consider posting the projects you use in the screen casts on your site?
I know there are many times, I would love to be able to peer through the code itself (in the event I missed you explaining something previously).
I'm still having the sound issues with this one. Does anyone else have a problem right about 37 seconds into the cast?
Just an FYI, I had to add
require 'rubygems'
at the top of my .irbrc file before this would work.
In reply to myself, it's bundled in Rails 2.1: http://mad.ly/2008/04/09/rails-21-time-zone-support-an-overview/#more-26
Bliss.
No need for the tzinfo gem?
@Eric, I would like to see more support for international users as well. Please do consider submitting a ticket/patch on this.
@David, this is actually generated by the TimeZone#to_s method, so you can override that if you want something different. That feels a bit hackish, so alternatively you can subclass TimeZone and pass that to the select field. I'm not sure if this will work though:
http://pastie.caboo.se/196823
You may want to submit ticket/patch for this.
When you use the time_zone_select in Rails 2.1 it also displays the time zones as an offset from UTC rather than GMT.
e.g. "(UTC-10:00) Hawaii" instead of "(GMT-10:00) Hawaii"
Its only a minor point, but UTC wont mean much to end users whereas GMT would.
Does anyone know if you can change this?
exactly what i was waiting for :P thx
Why exactly are you so worked up over this issue? There are rake tasks for all timezones and one that guesses your local timezone based on your system time.
While I agree having some degree of internationalization would be nice Rails has many other instances where specific internationalization support is not offered. The timezone Internationalization issue isn't really out of line with the existing core development philosophy.
lolz. then contribute one if you like. :)
Check out the above link for Extremely Simple PDF Generation in Rails using HTMLDOC
I feel very bad when I see such shortcut : #us_zones. US is not the center of the world.
Do we still think that US is more important than other countries ? Why not #russia_zones or #china_zones ? or at least #euro_zones ? or if we really want to be america centric why not #canada_zones ?
We shouldn't have such shortcut in the core, we should *never* have US be a prioritized value or even a default value. This is very bad practice.
Worse, we have a #us_zones and we don't even have a #utc_timezone or #gmt_timezone shortcut.
This's what I waiting for :) Thanks
What happens if in time_zone_select you want a different set of Zones to be up the top (i.e a non US application)
hi ryan,
i love your railscasts. i'm sure it helps pushing rails a lot.
my question:
is there a way to get ActiveResource objects when using custom methods like get instead of hash/array of hashes?
big up
chris
Yes, I am using submodules to track all plugins where possible. I like that it keeps a list of everything managed by git in a single .gitmodules file at the root of your main project.
Has anyone else noticed anything odd about the sound in some of these episodes (for example this one)? I'm using Quicktime on Windows and at 5:47 seconds there is a small cutout in the sound, and if you look at the timer in the lower left hand corner it stops updating for about 2 seconds and skips to 5:50. There are a couple of other points where it does the same thing, and I've heard in it a few other railscasts, and I'm wondering if it is just my system, can anyone else verify this?
Ничего не получается!
при импорте пишет:
svn: No repository found
Oh, while on the subject of using git to pull in external repositories, this post by Graeme Mathieson might be useful to people:
http://woss.name/2008/04/09/using-git-submodules-to-track-vendorrails/
Hey Ryan,
nice screencast (as always). Is there any chance you could clarify the repercussions of cloning an external git repository (as you suggest) inside a project which itself is already managed by git.?
So far I have been using braid (http://github.com/evilchelu/braid/tree/master) to pull in external git repositories (which I think links to the repositories as a submodule in a separate branch). This is mainly because I assumed there might be issues with storing git repositories within git repositories. However, I may be wrong...
Anway, suffice to say, a lot of this git stuff is still new to me, and probably a lot of other people too :-)
Thanks a lot, Ryan!
This was short and to the point, exactly what I was looking for.
Keep up the great work!
@Mike, interesting, I'm not familiar with that error. Perhaps post it on the mailing list along with the steps took to trigger it.
groups.google.com/group/rubyonrails-talk
there's no other traces of ruby on my ststem aside from what is shipped with leopard
:(
Yes it does work with helpers provided that you actually load the correct part of the yaml file.
Thank again, Ryan!
@Mike
Try removing any other versions of Ruby apart from the one that ships with OS X 10.5. (The MacPorts install of Ruby was occasionally causing this conflict after I upgraded.)
The best feature of rails 2.1:
3 railscasts a week.. WOHOO!
go Ryan!
Hello Ryan
great tutorial ! And I look forward new tutorial like Observer and State issue.
Thank you
Daniel
Hello Ryan (and railscasts guys),
I'm trying to render a layout through rjs but it looks like Rails doesn't render it.
page.replace_html :wrap, :layout => "details", :object => @task do
...
end
Am I missing something or Rails doesn't allow rendering a layout into a rjs file?
THANKS
Nice episode as always :) I have watched all your episode and as a result I have learned a whole lot about how to develop Rails applications. I have been trying these past days to find a good tutorial on how to upload files, images to be exact :). Is it possible you could do an episode on how to do this in Rails 2.1 in the near future? I have done a little experimenting with Django and uploading images there is very simple. I have followed a few Rails examples on this but they seem out-dated and "hackish". Sorry about the long comment, keep up the excellent work. I look forward to a new episode every Monday 8-)
Can this be used with Helpers?
If so, what am I missing?
I'm getting a template error when using a method defined in application_helper.rb to return the key in that appears to be nil.
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
Thanks.
I'm getting this error when I try to run anything like the about, console or server scripts
/Library/Ruby/Site/1.8/rubygems.rb:139:in `activate':Gem::Exception: can't activate activesupport (>= 1.4.1), already activated activesupport-2.0.991]
@Peter
Thanks for the answers. Glad I asked. I'm trying to get started with Rails (working through Agile...) and hard to figure out how all the Rails and Ruby pieces fit together particularly since so many new pieces being developed: Merb, Rubinus, Passenger, Rack, Mongrel, RSpec, Mephisto etc. Trying to figure out what I need to pay attention to and what I don't.
@Fred, that should work too, and I should have mentioned it. I just prefer to update an individual project through the vendor directory so I don't unintentionally update another project. At least until the final 2.1 is released.
Don't forget Mofo: http://errtheblog.com/posts/78-feeds-for-free.
It promises a way of talking Atom without writing separate Atom views.
@Fred: There are a few reasons.
First, I'm not certain that the RC is available as a gem yet.
Even is if is, there are a couple reasons this might be better.
1. You don't want to upgrade every app running on your machine before you've had a chance to check out how the new framework will affect your code. So installing Rails into the vendor directory is a little "safer" in that it breaks one app instead of all of your apps.
2. A lot of rubyists are on shared hosts and can't run "sudo gem install" anything.