RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Ryan,

Great episode!

I tried to reproduce the issue you mentioned about uploading files with an incorrect content-type, while using the validates_attachment_content_type validation:

http://gist.github.com/192625

However, Paperclip seems to handle these properly. It seems that this validation does more than its name implies ;-).

Avatar

Any updates from anyone re best Authorization approach to mesh in with authlogic?

Avatar

@Stefan (#33):

You can save the file in your view (not really pretty, I know ...)

pdf.render_file "tmp/example.pdf" #relative to RAILS_ROOT

Avatar

Is it possible to pass a SQL limit?

Avatar

Simply shaweet, I've wasted so many hours trying to clean up my css before. This is going to help a ton. Thanks Ryan... again.

Avatar

Nice SC Ryan,

  I was looking for something like this for a few weeks now but I still can't find a 100% working solution. The problem is having to deal with lots of pages (1000+) some of which are dynamically generated (and have generated urls). Now removing any css style from a huge website might break something somewhere so unless there's a 100% solution, this is very hard to do.

Cheers,
Cezar

Avatar

This is fabulous. I am saved from having to bother improving the documentation!

Folks like Seth have been stellar, since I rarely have the time to work on the thing myself. As he said, we can get some pretty rad features into master as soon as we've got tests for them, so if anyone has a bit of time to do that I would be very grateful.

Avatar

Fantastic episode.Its a quick and easy way to generate tree page navigation.

Avatar

Awesome! I almost gave up doing AJAX based pagination then this comes out!

Avatar

Hi Ryan,

I have two text_field_tag in my view.

In the first text_field_tag, I can enter name, category or description.

In the second text_field_tag, I can enter city, state or zip.

Right now I am using form_tag.

How can I use form_for to use order in above situation?

Avatar

Thank you for this Railscast. Your work is slowly helping me understand the more interesting side of rails.
The on issue I felt would have been nice here would be how to use the @accounts in your view. This would have complete the information needed to create the HABTM. I.E. if we had a user with an account and wanted to pull up the account for the user as a view, how would one use this?

Thanks Again.

Avatar

Since this project seems to use restful_authentication, and the newer episodes have moved to authlogic, I have been refactoring this tutorial to work with authlogic -- a good way to learn!

Avatar

any php / shell solution for CSS Diet Program ? thanks.

Avatar

"As Rayn mentioned if you add nil? check on the getter method it should wotk fine!"

No. The code is outdated for use today. There are more efficient ways to do this now.

Avatar

Great job on the casts dude. Perfect!

Avatar

Cool Stuff. I've always wondered if there was a way to refactor my visual code, but with no kind of layout tests, i didn't see how it was possible.

Avatar

I have always known that style-sheets will eventually contain unused selectors, but I never would have thought to look for a utility native to rails for hunting them down. Thank you for the insight!

Avatar

Ryan, Great Railscast, It would be cool if it could hook into Selenium and find out what selectors are being used by elements inserting into the DOM via JavaScript.

Or what if it could just look at my builders and know about the errors and flash messages... that would be cool too. Otherwise I still love the gem and think it is excellent.

Also I bet when you said: "rake deadweight... say that three times fast" 85% of the people watching said it under their breath three times...

Avatar

Ryan, Great Railscast, It would be cool if it could hook into Selenium and find out what selectors are being used by elements inserting into the DOM via JavaScript.

Or what if it could just look at my builders and know about the errors and flash messages... that would be cool too. Otherwise I still love the gem and think it is excellent.

Also I bet when you said: "rake deadweight... say that three times fast" 85% of the people watching said it under their breath three times...

Avatar

Err, better partially merged GitHub link: http://github.com/aanand/deadweight/tree/cli

Avatar

I added a command-line tool and an HTTP proxy to make deadweight a bit more flexible a couple weeks ago: http://mojodna.net/2009/09/08/csspring-cleaning.html

It hasn't been merged into aanand's master branch yet because it needs a few tests (care to help?): http://github.com/mojodna/deadweight

Avatar

OMG Ryan you are a life saver! I just started working on a site that has 7000 lines of css and was pondering how to cut some of the fat. Thanks a million

Avatar

oops,I think we just need it. :)

although I havn't look into it,but I think it should be very useful, good job,Ryan!

Avatar

Is there anything like this for finding deadweight partials and other view elements?

Avatar

Another great one. Many thanks.

Avatar

Another great episode! Thanks for your great work Ryan!

Avatar

Do you have some kind of precog abilities ? This is so spot on with what I wanted to investigate this week :)

thanks for all your work, that's just amazing.

Avatar

Ryan, you have an unbelievable talent to create Railscasts for things almost as soon as I think to myself "I wish I knew how to do #{x}".

It's amazing. Keep it up.

Avatar

Post
# Indexes for thinking
sphinx define_index do
indexes title
indexes abstract
indexes body
#indexes comments.body, :as => :comment_content
# OPTIONAL: keeps search index update
# First, add a boolean column to your model,
# named 'delta', and have it default to true.
# Then uncomment following line.
#set_property :delta => true
end

belongs_to :blog
has_many :comments
# GET published posts
named_scope :published, :conditions => [ 'published = ?', true ]
------
Comment
belongs_to :post
------

In my search action i have
blog.posts.published.search ( params[:search] )
i am unable to figure out error.

Missing Attribute for Foreign
Key channel_feature_id

here is full trace.......
vendor/plugins/thinking-sphinx/lib/thinking_sphinx/active_record/has_many_a ssociation.rb:18:in
`search'
/home/sandip/.gem/ruby/1.8/gems/activerecord-2.1.2/lib/active_record/named_ scope.rb:158:in
`send'
/home/sandip/.gem/ruby/1.8/gems/activerecord-2.1.2/lib/active_record/named_ scope.rb:158:in
`method_missing'
/home/sandip/.gem/ruby/1.8/gems/activerecord-2.1.2/lib/active_record/base.r b:1857:in
`with_scope'
/home/sandip/.gem/ruby/1.8/gems/activerecord-2.1.2/lib/active_record/associ ations/association_proxy.rb:164:in
`send'
/home/sandip/.gem/ruby/1.8/gems/activerecord-2.1.2/lib/active_record/associ ations/association_proxy.rb:164:in
`with_scope'
(__DELEGATION__):2:in `__send__'
(__DELEGATION__):2:in `with_scope'
app/controllers/blogs_controller.rb:36:in `search'

Avatar

Geez Ryan, it's barely monday (it's 2.04 cst) and here is your new screencast!

The very little (and good) stuff I know of Rails it's because of you!

Keep up the good work!

Avatar

nice work

Avatar

Could it be possible to have a named_scope that include columns from another association?

something like:
named_scope :my_fields,:select => "..."
or maybe another way?

Thanks

Avatar

Add a validates_presence_of :name to the product model, and try updating a product with a blank name and modified checkbox values. It won't save the product, but it will have updated the habtm records.

Avatar

fyi, I just posted a screencast on my new SaasRamp plugin for doing recurring billing for software as a service (saas)
http://www.vaporbase.com/postings/SaasRamp_Screencast

Avatar

This seems to be a way to train consumers to a new model and expectation for "using" this content in a way that is perceived as "legal".
really

Avatar

Nice Tut! I think I may use this concept for my site. (currently implementing a new RoR tutorial system).

Had some random not working at some point with it, but I just changed the username and password and for some strange reason that fixed it.

Thanks Again,

Joe

Avatar

This was a really useful episode, ROR really is awesome in that it lets you write code like that!

Avatar

Useful podcast, I was just wondering how to use other form objects and treat them differently using the 'rails' way; this making the controller behave differently due to model feedback should have been obvious but now it is. Thanks, nice cast.

Avatar

As henry mentioned, subclasses of a controller will use the parent's layout unless overridden. That explains why application.html.erb will be used as default if no other layout is specified.

Avatar

I have tried many different methods, the one shown here, and other ajax form plugins for jquery, and none of them trigger the JS respond_to block in my controller! The request is sent to the controller in the background, but my create.js file is not activated by the controller. I am runny rails 2.3.3 and jQuery 1.3.1
I really can't put my finger on why it is not activating the respond_to block.....

Avatar

This cast really is very, very nicely done. I loved watching the HTML form return data being handled very nicely by the rails framework.

Nicely explained as well. The biggest magic was the "product[category_ids][]".

Avatar

If you remove the index route for comments the delete links will break. Is there any work around for this?

Great Work Ryan! I just started using Rails 6 months ago and watched all 170+ screen casts as I learned.

Avatar

Interesting topic even tho I am not really impressed by scrapi, I hope to see some alternatives (maybe hpricot)

Thanks for another great screencast!

Avatar

@hartwig @Ryan @eric,
i have the same problem with the or-condition. i.e. User.search(:firstname_or_lastname_like => "foo") is not working. In the console i get the notice: #<Searchlogic::Search:0x34503f0 @conditions={:firstname_like_or_lastname_like=>false}, @current_scope=nil, @klass=User(id: integer, ....
Has anyone found a solution to this problem?
Great post thought, Ryan. As always.

Avatar

You may want to ignore stuff like .DS_Store in a global .gitignore file rather than your project's .gitignore file simply because there's never a case in any type of project where that should be checked into source control.

Use the global core.excludesfile configuration variable for this, and just set it to ~/.gitignore.

Avatar

Hi, When I try adding this to my project I keep getting an error, which I've mentioned below. I've slightly changed it where I'm not dooing the 3.times. Apart from that I think its pretty much the same. Can someone please help? I'm new to rails, so please be gentle :)

When I add this to my project I get the following error:

NoMethodError (undefined method `build' for ["name", "peter"]:Array):
  app/models/look.rb:6:in `business_card_attributes='
  app/models/look.rb:5:in `each'
  app/models/look.rb:5:in `business_card_attributes='
  app/controllers/looks_controller.rb:17:in `new'
  app/controllers/looks_controller.rb:17:in `create'

this is what I get from my params:

Processing LooksController#create (for 127.0.0.1 at 2009-09-16 22:04:34) [POST]
  Parameters: {"commit"=>"Submit", "look"=>{"business_card_attributes"=>{"name"=>"peter", "title"=>"director"}, "name"=>"test", "intro"=>"new"}, "authenticity_token"=>
"OpvpZZMCmEGYt/MOC21xXiyeYAb+0WIZ090giSNn9Rg="}

this is my form:

<% fields_for "look[business_card_attributes]", @business_card do |business_form| %>
<p>
     <%= business_form.label :name %><br />
<%= business_form.text_field :name %>
</p>
<p>
     <%= business_form.label :title %><br />
<%= business_form.text_field :title %>
</p>
<% end %>

this is my model:

class Look < ActiveRecord::Base
  has_one :business_card
  
  def business_card_attributes=(business_card_attributes)
    business_card_attributes.each do |attributes|
      attributes.build(attributes)
    end
  end
  
end

Avatar

I think the countries seed should use

Country.find_or_create_by_name_and_code(name, code)

so that you don't delete the countries that are referenced by other tables (if you chose to do that)

Avatar

@Nic, the controller call render to create a response to send back to the browser, and any instance variables you require in the view must be set up first.

Avatar

Hi Ryan,

in terms of the addition of

params[:project][:existing_task_attributes] ||= {}

in the controller (update), this was causing a problem for me, so I removed it and all works fine.

However, by removing this, would you see any implications? I know you use if when checking for existing attributes (of course), but in my case I have a nested model where the child model is created when the parent model is created and can contain blank field. Therefore, it doesn't matter about checking for new or current attributes...I simply have attributes whatever.

As such, what is the purpose of this line of code?

Many thanks,

Doc