RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Somebody tried to write specs for this episode?

Avatar

Hi Steve,

in case you're still interested, this is how I set to add specs for an implementation based on this Railscast:

https://gist.github.com/antillas21/9a326abfb690d0c26306

Avatar

Hi Rob... in case you're still interested, this is how I set to add specs for an implementation based on this Railscast:

https://gist.github.com/antillas21/9a326abfb690d0c26306

Avatar

Following your suggestion (echoed by Aaron Patterson) that thin is a suitable (ie., non-buffering) server, and since my requirement is fairly simple, I'm trying to get Live to work on the generic thin server. But no matter what I do it appears to buffer its output, so the client sees nothing from my response stream until the whole thing is done. When I switch over to puma it works fine, so the problem must lie with thin, but I can't get it to stop buffering the response to save my life. Any ideas?

Avatar

Trying to follow this tutorial with Rails 4 but getting a 'RuntimeError' when trying to insert the tags_list into the view.

Do I need to change anything for Rails 4? Do I need to do anything with the 'attr_accessible' method, as this is moved for Rails 4?

Avatar

Why not use the database store in development. Add all translations you want, then export from DB to yaml file which is used in production?

Avatar

Mindblowing. Not enough words for it. This just convinced me to subscribe to watch all the code walkthrough episodes. Thanks a lot for the great work.

Avatar

I wonder which color scheme do you use in this video ? I really liked it, it reminds me of coffee with all those shades of brown :)

Avatar

FYI - To get this to work in Rails 4 (I just generated the questions for my example so you will need to add for answers), you need to add to the bottom of the Survey Controller:

def survey_params
params.require(:survey).permit(:name, questions_attributes: [:id, :content])
end

Avatar

Howdy,

Today (10/18/2013) I went to play the video and it will not load

"Can't Play video Media Source loading has failed"

Could someone look into this please? Your other railscasts work fine.

Thanks,

Bill

Avatar

If someone is interested, I wrote a blog post on how to implement multi tenancy with Devise and default scope but without subdomains. This is useful when you don't want or can't use subdomains or for example when you only enable subdomains as a premium feature, meaning that your application needs to have multi tenancy both with and without subdomains.

http://vitobotta.com/rails-multi-tenancy-devise-default-scope/

Avatar

How do I test this?

I tried:

ruby
# RSpec + Shoulda
it {should have_many(:comments).as(:commentable) }

But it doesn't work.

Avatar

yes, line 6 in entries_index.js.coffee must be
@collection.on('sync', @render, this)

It is supposed to be 'sync' not 'reset'

Cheers!

Avatar

I don't know if this has been mentioned yet, but for me, the EntriesIndex would not update using the provided code. I had to change line 6 of entries_index.js.coffee from this:
@collection.on('reset', @render, this)
to this:
@collection.on('sync', @render, this)

To make it work.

Cheers.

Avatar

works pretty well for me but am trying to associate the photo to a particular user which i know how to, but how do i code the create, index and show action in the paintings controller?

Avatar

Hey kevin, have you guys been able to solve this? I think you are on to something withe versions, but I can't seem to work it out.

Avatar

I document all of the challenges I worked through in this episode here: http://devetc.tumblr.com/post/64332554082/fumbling-my-way-through-devise-and-omniauth

In general they were

1) 401 issues related to OAuth
2) Issues with adding an extra option to a definition in the user.rb model file
3) Getting stuck at https://api.twitter.com/oauth/authenticate when trying to authenticate

Avatar

Hey someone, I have made it a good way through this tutorial trying to make it work on rails 4, and have encountered a problem Im stuck at about 6mins 30 secs in. I think its my render partial, I have probably done something wrong, anyways I after upload images my render partial does not refresh, it adds the new image and all other images under the image that was already attached. So if I add two images to a new item it shows the first image, then renders the partial again with the first image and the second image under the first so there are 3 photos in total. I'm kinda lost any help would be great!

Avatar

I'm having the same issue with Windows Excel (2007) the file opens correctly just throws that error every time.

Avatar

Why couldn't you do

ruby
render "activities/#{activity.trackable_type.underscore}/#{activity.action}", activity.trackable_type.underscore.to_sym => activity

instead of creating the presenter. This seems much easier and less cluttered.

Avatar

Hi Jamie Barton, you are absolutely right. This was written very late in the night and out of frustration. I have most of this working now. Thanks.

Avatar

Don't be silly.

Use the version of Rails shown in this episode and then learn yourself by trying to make it work or find the answer online to comply with Rails 4.

:)

Avatar

Please update for Rails 4 kinda useless now.

Avatar

This needs to be refactored for Rails 4 bigtime.

Avatar

I did it all right but it´s not working.
Uploading and cropping images by giving values to the hidden inputs works right, but the dashed points to crop the selected area on the image doesn´t appear!

When a image is uploaded I get an error in javascript:

crop.html.erb
TypeError: $(...).Jcrop is not a function

heeeelp!

Avatar

this thing happend to me too so i changed the code to look like yours but now all the validations pop up every time =(
and i cant get it to work as intended

Avatar

I had the same problem. Didn't quite figure out what was causing it, but upgrading the gem file to Rails 4 fixed it. Just add/update these gems.

gem 'rails', '4.0.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'protected_attributes'
Avatar

Is there a way to generate the different versions for the default_url? Ideally, I'd like this to match the versions defined in the uploader.

Avatar

I'm crying laughing at that xkcd comic. Let's be friends =)

Avatar

I'm getting a Session Error. From what i read this is a problem with simple_from and Active Admin.. Is there any Solution ?

Avatar

Looks like there's an typo in the ascii casts in the listing for /app/views/locations/show.html.erb

The first few lines look like it was duplicated and pasted in in the wrong place.

Avatar

Any Idea on how I can customize the tag_cloud to only show the top ten tags. I am also doing it from scratch.

Avatar

hi!.

as I can decrypt the password?

I'm using the following:

ruby

<%= Sorcery::CryptoProviders::AES256.decrypt(user.crypted_password) =>

But the result is:
Sorcery::CryptoProviders::AES256 expects a 32 bytes long key. Please use Sorcery::Model::Config.encryption_key to set it.

There is another way to decrypt the password?

Avatar

@Dave Johnson, in case you were must have been using "has many through" and were getting this error.
Your join table should not contain the column "skill_ids",it should have skill_id.
That would solve the problem.

Reply is late but will help others :)

Avatar

Thanks for reporting this error and my apologies for the late reply. I have now corrected the ASCIIcast.

Avatar

In 1 mim resolved all of my problem tks..
came back please srsrsr

Avatar

I don't think it's necessary to call the klass method to get a new object in the helper. We can call #new or #build on the association directly like this:

ruby
new_object = f.object.send(association).new

One point that is probably obvious for most people, but confused me at first was why we would need to swap the object_id that's set in the helper for a time value in the javascript. I was thinking along the lines of: "the object_id is already unique, right?"

Well, yes and no. A unique object_id will be generated each time the helper is called to create an "add_fields" link. But that link may then be clicked multiple times. Each time it's clicked, it's going to generate a collection of nested fields named with the same object_id. Then of course, when the form is saved only one of those records is going to be created.

Avatar

Can't get the server to start. After running "$ rackup private_pub.ru -s thin -E production", nothing really happens. Can anyone point out why that's happening?

Avatar

Can't get the server to start. After running "$ rackup private_pub.ru -s thin -E production", nothing really happens. Can anyone point out why that's happening?

Avatar
your model
serialize :properties, ActiveRecord::Coders::Hstore
Avatar

In case it might help someone, I switch from creating a class in app/datatables to use Jbuilder.

This gave me the huge advantage to use cache. I tried delegating the cache method in my class but with no success...

Here is an example:

product_controller.rb
def index
  @products = Products.all.page(1).per(50)
end
products/index.json.jbuilder
json.sEcho params[:sEcho].to_i
json.iTotalRecords @products.total_count
json.iTotalDisplayRecords @products.total_count
json.set! :aaData do
  json.array! @products, partial: 'show', as: :product
end
products/_show.json.jbuilder
json.cache! [product] do
  json.id product.id
  json.name product.name
end

hope this helps (Im using kaminari)

Avatar

great episode, but i wish it had more info on how to set up and create a PostgreSQL database for new Postgres users. It would of definitely helped when migrating

Avatar

Just wanted to let everyone know that this railscast is still proving to be successful on Ubuntu 13.04 server.

Remember, if you are going through any of Ryan's amazing Railscasts or any tutorial for that matter, make sure you clear your browser cache frequently!!!!(or turn it off)

I had everything working perfectly after a few fixes (unbeknownst to me) but I continued to see errors in my browser. I then stupidly searched for solutions to the problems (...that I had already fixed) for about 30 minutes, finally deciding to launch Chrome, which I mainly use for UI consistency...and, you guessed it, everything was working as it should. I shouldn't be making these rookie mistakes this late in the game.

Ryan you are amazing and I don't say that to many people. Quality, quality work as usual!

If anyone is trying to deploy to a server running Ubuntu 13.04, I will try my best to help you!

Avatar

I ended up re-doing this in Rails 4, Bootstrap 3, and Sass. Check out the repo and README here: https://github.com/ivanoats/store-rails4-boot3-sass

Avatar

I came up with this solution to bidirectional with methods for:
* mutual - relationship in both directions
* pending - relationship only forward
* requesting - relationship only backward

ruby friend.rb
class Friend < ActiveRecord::Base
  belongs_to :profile
  belongs_to :friend, :class_name => 'Profile'
end
ruby profile.rb
class Profile < ActiveRecord::Base
    has_many  :friends
    has_many  :friend_profiles, :through => :friends, source: :friend
    has_many  :friended_by, class_name: "Friend"  , :foreign_key => "friend_id"
    has_many  :friended_by_profiles, :through => :friended_by, source: :profile
   
    
    def mutual_friends
      friended_by.where('profile_id in (?)', friend_profile_ids)
    end
    
    def mutual_friend_profiles
      Profile.where('id in (?)', mutual_friends.pluck(:profile_id))
    end
    
    def requesting_friends
      friended_by.where('profile_id not in (?)', friend_profile_ids)
    end
    
    def requesting_friend_profiles
      Profile.where('id in (?)', requesting_friends.pluck(:profile_id))
    end
    
    def pending_friends
      friends.where('friend_id not in (?)', friended_by_profile_ids)
    end
    
    def pending_friend_profiles
      Profile.where('id in (?)', pending_friends.pluck(:friend_id))
    end
end

Any suggestions for improvement?

Avatar

You can use build_stubbed, that will build object with stubbed associations.