RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

I started using Highcharts as a direct result of seeing this screen cast. Thanks for alerting me to it!

I'd like to add something after having used Highcharts for a while:
Highcharts expects the data to be in json format, so the "to_json" function is key when passing data to HighCharts. Calling "inspect", which is the technique used in the screencast, is only going to work on arrays.

Avatar

Ryan,

Thanks so much for cool casts !!

Btw, I have a little problem implementing vestal_versions as followed from this episode.

It'd be so kind if you'd have some solutions to this

http://railsforum.com/viewtopic.php?pid=132945#p132945

Avatar

I've been using MongoID for a couple of months now, and I love it!

One thing I like particularly about MongoID is that it uses
include , rather than sub-classing, to add the persistence to a class!

That's much cleaner, and allows you to use sub-classing when you really need it for _your_ models/application..

Avatar

Good one, Thank you.

Avatar
Christian Fazzini on #238 Mongoid 2010-11-05 03:27:03

Ok, figured it out. build() instead of create() seems to invoke save() for the respond_to block

Avatar
Christian Fazzini on #238 Mongoid 2010-11-05 02:36:02

in follow-up to my post at #30. In case you are wondering, I need the respond_to block for ajax:

  format.js { flash[:notice] =
    'Comment was successfully
     created.' }

which also calls create.js.erb for further processing

Avatar
Christian Fazzini on #238 Mongoid 2010-11-05 02:25:02

In def create, what if you have a respond_to block? For example:

respond_to do |format|
  if @comment.save
....

How do you check if the save was successful?

Currently you are using create: @comment = @article.comments.create!(params[:comment]), which doesnt return true or false

Avatar

Can you use Omniauth to authorize for two different Twitter accounts so that you can tweet to both in your app at the same time?

Avatar

Thanks a lot for the episode. I'm starting to use mongoid and looking for a solution of a query case: formate a Datetime field to be like "YYYY/MM/DD" and group by this field, and then select the max value of another Integer field of each group. This should not be difficult for a sql datebase. Went through mongoid documentation, but found nothing helpful.

Avatar

Thanks for the cast. Does anyone else have to problem with playing the iPhone version on iPhone? Since few episodes ago, I cannot play those anymore (format not supported).

Avatar

Now I'm wondering if action caching will work with pagination. I tried a couple of different things but I can't seem to get it to work. I was just wondering before I go to a lot of recoding on my existing blog to add this.

Avatar

Thanks, concise and helpful as always.

One quick comment regarding my experience: I could not make the file upload work using paperclip in a formtastic form; it worked fine in a standard rails form though. If anyone has a solution for making paperclip and formtastic play together nicely, I would be interested to hear about it.

Also, I would be interested to see a railscasts episode regarding file download.

Thanks,
-c

Avatar

Thanks for the great post!

Is there a way to tell test_unit to setup factory_girl in the functional tests?
Using g.fixture_replacement :factory_girl
still puts by default fixture alike setup in the controller test, example:

class PostsControllerTest < ActionController::TestCase
  setup do
    @post = posts(:one)
  end
...
end

Avatar

Hi, I got the same error that rafita. How i can solve this problem?
Thanks

Avatar

wonderful information for us, thank you! best wishes for you!

Avatar

I'm a noob, so forgive me if what I write is not the correct procedure. After spending a couple of evenings on this, I managed to get this working for Rails 3 with the following changes (I'm trying to summarize all the experiences above).

1. Changed cropper.rb to this
http://pastie.org/995357
(From Chris Your)

2. Move cropper.rb to the folder config\initializers

3. Added missing '=' in crop.html.erb:
...
<%= form_for @user do |f| %>
...

4. Remember to add crop_x, crop_y, Crop_w and crop_h to the list of your accessible attributes IF you have such a list:
attr_accessible :avatar, :crop_x, :crop_y, :crop_w, :crop_h

5. Added this line to my gemfile:
gem 'paperclip'

6. bundle install

7. Being on windows, I added the path to ImageMagick in my development environment:
Paperclip.options[:command_path] = "C:\\Progra~1\\ImageMagick-6.6.5-Q16"

I used the SHORT path with ~1, because I read somewhere there was a problem with spaces here.

8. Added jquery.Jcrop.min.js, jquery-1.4.3.min.js in public\javascripts folder

9. added Jcrop.gif and jquery.Jcrop.css in public\stylesheets folder

10. Added <%= yield(:head) %> in the <head> section in the application.html.erb file (needed for sample above)

11. Restart your server

Pfeyy... Hope that helps someone, it took a while to sort all this out :)

Avatar

I had no idea about the cmd-opt-a hotkey. thank you so much!

Avatar

In rails 3 you should use :

<%= f.fields_form [...]

instead of :

<% f.fields_form

same goes with form_for

Avatar

In Rails 3.0.1 it seems that once a question is created it does not get removed if its blank. E.g. the way Ryan shows it does not work but when creating a new Survey blank questions do not get saved (correct way).

Avatar

Caveat using Rails 3.0.1 and Nifty Generators 0.4.2:
Nifty Generators will generate:
attr_accessible :name # which is not compatible with accepts_nested_attributes_for "this way" e.g. it (correctly) prevents nested attributes to be saved.

Maybe this should be added to a Rails3 update notice ;-)

King regards
 ionas

Avatar

xdrtfcygvuhbijno

Avatar

Thanks for all the episodes, they are all very useful.

Avatar

Ryan, thanks so much for your railscasts. They are very well structured along with sources and dependencies. I would drown in rails without those.

Avatar

Excellent as always. But I do think you are copying Steve Job's style. I heard you say awesome like 4 or 5 times in 10 minutes. Yes the iPad is a magical device and Mongoid is truly awesome. :)

Avatar

You may want to change the sort_column fuction to

    params[:sort] ||= "opp"

if you are finding that you cannot search on a column because you are running e.g. Post.includes(:categories)

Avatar

Thanks for this - it's a fantastic resource. I think I may have found a potential bug:

1) Sign up with a new account /auth/twitter
2) Once called back to your site, it will ask you to enter an email address
3) Go to /authentications and delete all authentication records
4) You will no longer be able to login (even by going to /auth/twitter again)

When it asks for your email address, it will say it's already in use.

Does anyone have a potential fix for this?

Thanks

Avatar

To answer my own question from comment 17, it was slow because I was creating objects on an association. Here's the comparison and a faster way to do the same:
http://gist.github.com/659961

Avatar

In response to questions about Rails 3 - It appears (from looking on the the github page issues section) that searchlogic is pretty heavily tied to ActiveRecord 2 and not trivial to switch over. There is a port in progress at railsdog/searchlogic currently in it's 3rd or fourth release candidate. I haven't been able to get it to work yet, but it's worth checking out.

Avatar

Hey Ryan,

Thanks a million for your awesome work. Have been following your RailsCasts for a year now, and you really helped me out of a lot of problems.

Maybe I am overlooking something, but isn't it possible to use self.abstract_class = true in this situation??

Many greetings,
Jakob

Avatar

As I understand common difference is generated HTML only.

Formtastic one is a bit complex

Avatar

Great one.. as always.
Thanks

Avatar

Very successful in both content and style sheets. Thanks webmaster and content editor
asd

Avatar

I set this up and then wrote a little loop that .creates an object. It seems to go at about 10 saves per second -- are there config options or something I need to get the legendary MongoDB write performance?

Avatar

That was great tutorial. After this I would love to see integration of mongoid with cucumber and pickle and it's steps.

Avatar

Ryan, you are awesome, truly one of the perfect examples of use of emerging technologies with the spirit of innovation & open source.

Can't tank you enough to be one of the leaders on my learning curve & inspiration in the Ruby & Rails world. Especially with expertise & agility.

Keep doing the great work.

Avatar

If you want a complete example application using Mongoid, take a look on GitHub at http://github.com/fortuity/rails3-mongoid-devise.

The example app integrates Mongoid with Devise, to give you quick development without schemas or migrations plus ready-made authentication. Gives you a skeleton or starter app you can deploy in minutes. Best of all, it's got a detailed tutorial (walk-through) to show how it's built. Follow the link above to see more.

Great to see a Railscast on Mongoid! Thanks, Ryan!

Avatar

Thanks, Ryan! Mongoid is very very awesome. One of the best-written ruby libraries out there, if you ask me.

Keep up the great work on Railscasts!

Avatar

Hey Ryan! Thanks again. Would you recommend using MongoDB for newbies to rails?

Avatar

Thanks for the episode!

I agree with previous comments that choosing between embedded and relational association is hard. I usually end up with the former.

The thing you *have to* keep in mind is also the BSON limit on document size. It's currently only 4MB, so you can imagine someone breaking your document with adding more data than allowed -- think about validates_length_of or something like that.

Avatar

@dotemacs: the bigger rails firms benefit from a vibrant rails community. I think that many newcomers and semipro rails developers learn much from the railscasts. This improves the pool to requite employees from. They also use open source plugins and gems for rails. In many cases the ones that makes these also get tricks form railscasts. I can send emails to some companies and ask them if there is any interest to donate Ryan some money every month.

If 10 firms donate 100$ every month, it could be a start.

I really would like to read more ideas. Be creative! We all can donate, but I do not think that will be a steady income source.
 

Avatar

As usual, great Episode Ryan!

@Erik: MongoDB performance is great, it's way faster than Mysql. I played around a bit and inserted 100.000 records in both Mongodb and Mysql on my MacBook and Mongodb finished the job in 1/3 of the time it took Mysql. However, MongoDB has some caveats you should know about: no transactions & no single server durability.

Keys are not meant to updated, so if you want your users to change their name, you will have to generate a slug (there is a gem for that).

Avatar

I agree with Andreas Lyngstad. Awesome job Ryan. I'd love more casts :) You have a gift for this.

Avatar

Hello,

I like what Ryan is doing and I agree with the posters above. I've actually been planning on donating and this just prompted me to action: I donated via PayPal.

Also, I don't see how big Rails companies will benefit from donating to Ryan, its more the indy devs and upcoming devs who'll get the most out of this.

Thanks

P.S. not that interested in Mongo, but I did enjoy and found useful many of the previous topics

Avatar

@Erik
About showing the latest comments (that is to say show all articles' last comment), I used to have similar fears as well. But then I stepped back and thought, how would I do it if it were on activerecord? In Activerecord, then, one would probably do well with aggregating all articles first, calling the first of comments ordered in desc time, which is same as in Mongoid.

If we were to display the absolute latest ONE comment, I can see the concern. And to solve it, allow me to attempt here, I would find the latest changed article because comment is embedded, adding a comment to an article is classify as the same act as updating that article, so that latest changed article should then contain the latest comment.

Avatar

MongoDB (and similar) looks like the bomb! Is this the death of traditional DB:s? Or is performance a bottle neck?

Anyway, about embeded assosciations I can see a problem when for instance on a first page you'd want to present the latest comments on all articles. This wouldn't be possible would it if the comments were to embedded?

Also! About the key, what if I want to let my users change their names? Is it possible to also update the key in such case?

Thank you!

ps. I would defintely pay for Railscast if it was subscription based. Maybe like $5 per month. ds.

Avatar

Deciding whether an association is relational or embedded is tough. Another criterion to add to Ryan's suggestion is whether the number of that associated model will grow to very large.

In case of comment, though you can have thousands sometimes, after awhile, the article becomes stale and very few new comments will be added and so an embedded association works well.

But take another example: users and tasks. Because some user will not likely to stop having new tasks, and an embedded association will always be loaded when calling the user (I could be wrong about this, if so this is not a concern then), so the loading time of a user model with great number of tasks will be quite slow.

In such cases as these, I wonder if there is a 'limit' operator to be put in the query to reduce the # of embedded models returned.

Thank You, Ryan, for the screencast

Avatar

Many thanks Ryan, just what I need !

Fully agree with Andreas Lyngstad post !!!

Avatar

@apneadiving I've found the devise branch to not be quite as flexible because it only allows a single model. It seems to work behind the scenes much like this railscast too.

I keep seeing @user floating around, where does that get defined? I don't see it explicitly.

I'm having a tough time trying to cleanly integrate two separate models. Right now I'm trying to use two separate models but have them share the authentications table.

Avatar

I posted this last week, but far down in the comments. I get the top here, so here goes. We could maybe move this to a forum somewhere.
Here goes:

I want to quote Ryan From the comments in another cast
" - However I hope to, at some point, have more time to dedicate to Railscasts and make it my full time job."
I think railscasts is very valuable. I use it all the time as a reference guide.

I think it would be a great thing for the rails community if Ryan can have railscasts a his full time job.

Does anybody agree?

Can we all pull together and come up with suggestions on how railscasts can be free and Ryan can get a full time job income?

Maybe big rails companies can, under a voluntary contract pay Ryan some money every month?
I guess they all benefit a great deal from these casts?