RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Ryan Boa Tarde!

Estou usando o código a seguir para popular algumas tabelas:

http://pastie.org/650693

Ocorre que se executar mais de uma vez, a sequence do postgres continua. Como poderia fazer para resetar a sequence sempre que rodar rake db:seed ???

Abraços

Avatar

the jrails site is a dead link : http://ennerchi.com/projects/jrails

Avatar

Also re: LoriBox's approach you might want to alter the conditions as such:

:conditions => ['lower(name) like ?', new_category_name.downcase ]

just a thought...

Avatar

Now it's possible to write an even better version of last_incomplete:

def last_incomplete
  @task = Task.find_last_by_complete(false)
end

Avatar

Ryan. Thank you.
You saved me hours with this link:
http://pastie.caboo.se/96864

Avatar

User.all(:joins => :comments, :select => "users.*, count(comments.id) as comments_count", :group => "users.id")

Ouch, don't do that or your code will not work on Oracle for example, in proper SQL, "group by" expression must contain ALL columns not in computed value (SUM, COUNT, etc..)

Avatar

Next weeks episode: filtering spam?

thanks

Avatar

For anyone who might be interested I have created a similar processor to handle rotation.

This was created because a) it seemed hacky using RMagick by hand when paperclip had all the bits available and b) it was the cleanest way to handle rotation with images hosted in S3 storage.

The required code can be found in the following gist: http://gist.github.com/206145

Enjoy!

Avatar

Ah, I see - add the code from http://railscasts.com/episodes/158-factories-not-fixtures

Avatar

Same problem as Mike:

no such file to load -- /Users/Foo/Projects/test/Rails/blog/spec/factories (MissingSourceFile)

Avatar

It's simple, it's elegant, and it's *awesome*! Best screencast ever! I'll recommend this episode to my PHP friends as well, I don't think they would mind :)

However, you should update your commenting system, because of the spam it collects.

I once had a simple commenting / voting system which was abandoned for a couple of years, and... umm... well, when I had a look on it, I had to remove about 20000 spam messages. And, the commenting feature.

Avatar

Hey Ryan,

Thanks for this. I am in the middle of developing an application that requires users to upload images and this is exactly the screen-cast I needed.

Also in the middle of learning how to use that GeoKit plugin... it's amazing.

Avatar

Hello Ryan,

I saw that you have now several episodes on background-processing options: system call+rake, whenever/cron + rake/runner, starling+workling and now delayed_job. Would you have one on BackgroundJob and how it fares against all these options you surveyed? It will be a great summary comparison reference. Besides, even though delayed_job is getting popular (e.g. github and what not), it seems that BackgroundJob is also heartily recommended (e.g. EngineYard) among the serious, production-ready contenders. It would be great to see what your take is on this. Thanks.

Avatar

In Rails 2.3.4 it says: undefined method `password_confirmation' for #<User:0x7f4ffda0a7e0>

I added an
  attr_accessor :password_confirmation

to the User-Model

But still got the Error:
Password confirmation is too short (minimum is 4 characters)

Avatar

In Rails 2.3.4 it says: undefined method `password_confirmation' for #<User:0x7f4ffda0a7e0>

I added an
  attr_accessor :password_confirmation

to the User-Model

But still got the Error:
Password confirmation is too short (minimum is 4 characters)

Avatar

One thing is not clear to me. Is the action dynamic_states expected to be called manually everytime the contries/states get changed? If not, how does it get invoked? In the tutorial, Ryan invoked the method directly using the URL. If that is not done, is this still going to work?

Avatar

Great railscast as usual.

Just one suggestion. For lists of countries and states, the Carmen gem is way better than copy-and-pasting:

http://github.com/jim/carmen

You also get some handy helpers to convert between full name and abbreviation.

Avatar

Awesome RailsCast as always!

Ryan, you might want to check your mail, you've got 138 new messages! :)

Avatar

It would be nice to see how to integrate Lockdown with Authlogic.

Avatar

Hi Ryan,
Another useful screencast! I would like to personally volunteer to weed out the spam and moderate the comments. I would suggest shutting down comments after a given time period. The amount of spam is crazy!

Avatar

hey Ryan

 there's been a lot of feedback here

1) care to respond to some of them at least?
2) a non-fully client side approach is to use Ajax. Could you please do a railscast on how to achieve the same effect using ajax?

Avatar

How can I share my passenger urls over web sharing. I'm working with someone on a webapp and I'd like them to be able to view it on their computer before it worked. They would put in my local ip (192.168.0.135:3000) and they could view the app. Is that possible now with passenger somehow? Thanks so much!!!

Avatar

Thanks Ryan! Great stuff.

I use the prototype alternative for this, I'm not a jQuery guy :)

Avatar

Hi Ryan! that good news was to see the new railscast appear.
I was wondering do you have something happened to the idol of Monday?
I also take your time to thank and congratulate the videos of "Everyday ActiveRecord" and "Mastering Rails Forms" are excellent.
Thanks and best regards from Chile!
Sincerely, Nelson.

Avatar

Ryan,

An excellent screencast as usual, which was actually quite timely as I was just wondering how to pass cropping parameters to Paperclip.

Also thanks for mentioning my Prototype & script.aculo.us cropper. It was very good timing as I was actually in the process of releasing a new version, which is now live.

@Nithin Bekal - if you don't want to use jQuery and prototype together then look into my cropper (mentioned in the screencast & linked to in the show notes) that is Prototype & script.aculo.us based.

Avatar

Hi Ryan!

This is an amazing screencast. I didn't know that something like that is possible in such a cool ruby-on-rails way.
It is definitely a very useful feature and absolutely an eyecatcher on a website.

Avatar

Hey Ryan,
Excellent screencast....really helpful and concise.

Also, why dont you add recaptcha to your comments section to avoid all the spammars!

Thanks again and great job.

Avatar

Ryan - I hope you can help me with this. We had a mess with our production database. We just upgraded from Rails 1.2 to 2.3.2, so we had a schema_info table, no schema_migrations table. When we ran command for migrations, instead of it recognizing via the old schema_info table that we were at migration 64, it just started running all the migrations starting with 1. I don't know why the automatic table replacement didn't occur, but now I need to figure out how to clean it up. Should I just delete the schema_info table and manually create/populate a schema_migrations table?

Avatar

Wow!

I am extremely impressed on the depth of this screencast. This is probably my new favorite. Please keep the more advanced screencasts coming. Outstanding job!

Avatar

Wow...cropping gets into some more heavyweight stuff, this is great. Thanks Ryan!

Avatar

Ryan,
One more time you made an awesome screencast!
Thanks a lot!

Avatar

Thanks for the screencast. I've been storing images directly in the databases in my current application, and have been looking for a good way to crop the images before saving.

But will Jcrop cause problems with prototype? I always seem to run into trouble when I use jquery plugins, although jquery works fine in noconflict mode.

Avatar

Hi, Ryan.

I couldn't believe my eyes when I saw my little rjcrop example in your screencast, it's a great honor. I learn so much from you every week that contributing back feels very good.

Greetings from Buenos Aires, Argentina.
 

Avatar

@iblue, good point. I think a quick "to_i" in the processor should solve this problem. I'll update the code.

Avatar

Ryan, u r so awesome!!!!! seriously, I was looking for ways to do this last week and now you've done an episode for us.

Avatar

Ryan, I'm not sure, but what happens if some evil attacker modifies the crop_* parameter to something like `dd if=/dev/zero of=/dev/hda` or any other evil stuff?

Wouldn't that lead to a remote command injection vulerability in cropper.rb, line 14?

Avatar

This....is cool...

Great timing too; I was just thinking over the weekend that this would be a great feature for one of my projects.

Avatar

Great cast! I didn't know that digging into the Paperclip processors was that accessible. I'd love to figure out how to rock some rounded corners or other such coolness.

Avatar

Thanks again, Ryan. Anybody know of a similar plugin or jslib for drawing on an image?

Avatar

Ryan, thank you for another great cast. Even though it was a bit late, it was well worth the wait. Also thanks to jschwindt for creating a great tool.

Avatar

You keep surpassing my expectations every monday. Exactly what I was looking for in my on-going project, many thanks for the time you spend at creating these screencasts.

Avatar

Here you can find the same but in PDF format:

http://media.pragprog.com/titles/fr_arr/multiple_models_one_form.pdf

Avatar

I am not able to get validation message on update. Kindly help me in this...

Avatar

Another security hole: filtering fields from serialized objects.

If you set up your users using default RESTful routes, then
  /users/:id.xml
will show all fields by default, including (if they exist) the persistence-token, crypted password, salt, email address and openid.

You can disable the formatted routes, or you can sanitize these fields by overriding to_xml, to_json, etc to always use the
     :only => [...whitelisted fields...]
flag.

I have a plugin at http://github.com/mrflip/attr_visible that helps set defaults for the serialization methods.

----------

Also be thoughtful about fields that should be writeable on create but not on update: for example, username, or an "I agree to these terms" flag. Remember, even if they're not present in the form they can be submitted as params.

Avatar

When I click the destroy link I get the following error:

TypeError: Result of expression '$(element).next('.should_destroy')' [undefined] is not an object.

Have double checked the code, and all other aspects work. Any thoughts?

Avatar

I noticed you used a 'ss' shortcut/alias to start your server. How might you do that Ryan?

Avatar

Is it possible to do sorting on two columns like:

ascend_by_last_name.ascend_by_first_name?

It seems searchlogic ignores the second ordering command.

Avatar

Trying to implement this sort of functionality into my site, but having some small problems.

1. I'm using the restful authentication plugin

2. Each "user" has_one "Profile".

Here is my question & problem:

1. Should I associate the friendship with the Profile_id or the User_id? Is one more efficient than the other?

2. How can I get the Profile_id into the create method of the friendships_controller? (if that's what I end up using)

PS - Love your screencasts consistently blown away...

Avatar

This is great! Just what I needed! One comment - this doesn't work so well with a datetime_select:

# projects_helper.rb
def fields_for_task(task, &block)
  prefix = task.new_record? ? 'new' : 'existing'
  fields_for("project[#{prefix}_task_attributes][]", task, &block)
end

Results in:

/!\ FAILSAFE /!\ Thu Oct 01 14:11:41 -0400 2009
  Status: 500 Internal Server Error
  expected Hash (got Array) for param `new_broadcast_attributes'

I had to hack it to look something like this:

def fields_for_task(task, &block)
    projectattributes = task.new_record? ? 'new_task_attributes][][' : 'existing_task_attributes]['
    fields_for("event[#{projectattributes}]", task, &block)
  end

Datetime_select on a new project would fill in the empty [] with its own data. This wasn't a problem on an edit since the [] contained a task ID.