RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Thanks for reporting those inconsistencies, I have corrected the ASCIIcast.

Avatar

Thanks for reporting that, I've corrected this error in the ASCIIcast.

Avatar

@laylester, could you please put out a sample/example on Github?
Thanks.
Bharat

Avatar

for the custom s3 uploader, how would i go about adding attributes to be added along with the created photo. such as user_id and photo_name

Avatar

it's because capistrano is loading bundler incorrectly.

to fix this, in your Gemfile, add both
gem 'capistrano'
gem 'rvm-capistrano'

In deploy.rb,
insert the following line at the top: require "rvm/capistrano"

it should solve the bundle not found issue

Avatar

If you want a multi-domain solution, I think you'd do that configuration in your front-end web-server/proxy, configuring nginx/apache to handle multiple vhosts.

Avatar

Hi. I am trying to implement a reset voting feature. So when a user voted up and clicks again on thumbs up, the vote should be reset. I tried to delete evaluation but it does not work. Any clue or someone implement something similar?
Thanks

Avatar

In order to test the dynamic generation of error pages, you need to be in production environment, which is incompatible with running your entire test suite, normally in test environment.

Similarly hacking the config.consider_all_requests_local parameter may is not viable except as a short-term hack to see dynamic error pages operating in dev or test environment.

So I found it best to move the ErrorsController and associated views into a Rails engine... that way it can have a test suite of its own, running the tests in production environment.

Avatar

For some strange reason I keep getting
ActionView::Template::Error (require_tree argument must be a directory

Avatar

Does anyone seem to get

ActionView::Template::Error (require_tree argument must be a directory

Avatar

I would think you resolved it long ago so this is more for anyone else viewing this part of the thread. I improved the RubyMine section out on the Wiki

Avatar

Hey everyone I figured out another solution. by adding:

listen [::]:80 ipv6only=on default_server;

after the

listing [::]:80

this answer was located here on stackoverflow here:

http://stackoverflow.com/questions/14972792/nginx-nginx-emerg-bind-to-80-failed-98-address-already-in-use

Thanks #Nathan

Avatar

Fantastic! This is so helpful, Ryan. Thanks.

Avatar

I think you're right about calling this a hack-fest. I think Ryan was alluding to that in the end, but covered it because it's a new core rails feature. But you have to keep in mind that if you need these services, you're going to have to integrate them somehow. I have found that Faye can be pretty fast, depending on your client side JS and architecture.

Avatar

Ok, last comment. I think this screencast should have included a complete Announcement resource with views, controller actions and model validations. It was fairly simple to wire up the controller and views to accomplish this. I assume it wasn't done as this screencast was focusing more on the test side. In my case, I used this as a guide to create an announcement function for a client site where the client needs to be able to easily manage his announcements.


Also was surprised by the number of small, but important typos in the ASCIIcast. Depending on your skill level, small mistakes can really throw you for a loop.

Avatar

I also just realized that later in the screencast after creating the announcement controller at /app/controllers/announcements_controller.rb the first line has protect_from_forgery which doesn't belong. That is already in the application_controller.rb


A bit farther down is a paragraph about: "Before we change current we’ll write some tests for the new functionality." that references /spec/announcement_spec.rb instead of /spec/models/announcement_spec.rb

Avatar

Following the ASCIIcast and just noticed a typo: "This test fails when we run it as our app doesn’t have an Application model. We’ll generate one now with the fields we use in our test then migrate the database."

I believe the Application should be Announcement

Avatar

While this tutorial is awesome the way it is, it falls flat at one thing that is more than not going to happen to you

ruby
Hosting Multiple Apps on the same VPS

Please address Capistrano

  1. Initial Server-wide software deploy:install that will not have to repeat for every app. Ex. nginx, postgresql installation tasks etc
  2. Initial Server-wide deploy:setup (configuration) tasks
  3. App specific deploy:cold (configuration) tasks

@ryanb could you see how to do that please.

Avatar

If you are using MongoID, than do this in your initializer:
Mongoid::Document.send(:include, ActiveModel::ForbiddenAttributesProtection)

Avatar

Wow! Been a RailsCasts member for about 2 weeks and I cannot believe how helpful it has been. Just when you think Google can answer everything, I stumble back here.

I have been looking for a good solution to conditional validations for almost 2 days. Stack Overflow had dozens of potential answers, but no "great" way to get this done.

Thanks Ryan!

Avatar

See my comment below for how to do this.

Avatar

To anyone trying to access instance variables from within the datatable controller, pass the instance variable to a method within a helper. For example:

ruby
# application_helper.rb
module ApplicationHelper
  def user_name
    @user.name
  end
end

# datatables/my_datatable.rb
class MyDatatable
   ...
   def hello_method
     "Hello, #{@view.user_name}"
   end
end
Avatar

I did a crude fix that seems to work. I basically just required the time_duration library from inside models/episode.rb.

ruby
require 'time_duration'

class Episode < ActiveRecord::Base
  ...
end

Please correct me if this is the wrong approach :)

Avatar

Is anybody else receiving this error?

To replicate you clone the repo for the episode, go into the after folder and run

bundle install
time bundle exec rake spec:models

I am using ruby 1.9.3-p385 and rbenv.

Episode translates single digit seconds into timecode with minutes
     Failure/Error: build(:episode, seconds: 60*8+3).timecode.should eq('8:03')
     NameError:
       uninitialized constant Episode::TimeDuration
     # ./app/models/episode.rb:8:in `duration'
     # ./app/models/episode.rb:5:in `timecode'
     # ./spec/models/episode_spec.rb:19:in `block (2 levels) in <top (required)>'
Avatar

Could someone please help me? I'm stuck early on in this Railscast. I cannot seem to get searching with multiple words working (as at approx 02:15 in the video) even though I am using the exact same code as below:

ruby
def self.text_search(query)
  if query.present?
    where("name @@ :q or content @@ :q", q: query)
  else
    scoped
  end
end

Single word searches work fine, just not two or more. I'm not getting any errors, just no results are returned. Any ideas why this could possibly be?

Avatar

+1
Was easy to debug, but still cost me 10 minutes...

Avatar

sorry about my comment, I was very angry that day; it works fine and the vids are great

Avatar

I had the same error - "An unexpected error has occurred. We have been notified of the problem."

I got it working following the Stripe tutorial (https://stripe.com/docs/tutorials/forms) which uses https://js.stripe.com/v2/ and has some differences, including the 'data-stripe' attribute.

Tried to add drop-downs for the expiry date and was told by Stripe support "The data-stripe version of Stripe.js doesn't support dropdowns yet (we're working to fix this). In the meantime, feel free to copy the old method from https://gist.github.com/boucher/1750368)"

Avatar

No, Pierre's code simply saves you from having to define a method called topic, and a different one called user, with mostly the same implementation.

Avatar

You don't have a topic_attributes method on every class. You have only one shared method in all controllers and views, called permitted_params. The object returned by that method has methods like topic_attributes inside of it.

Keep in mind that in controllers there is already a shared method called params. I think this solution is very much inline with rails' way of doing things (which you might or might not like).

Avatar

You are right. Sometimes there where multiple ajax requests.
This script only fires one time, removes the eventlistener on scroll end adds it when finished.

This works with turbolinks.

coffeescript
onEndless = ->
  $(window).off 'scroll', onEndless
  url = $('.paginator .next a').attr('href')
  $('.paginator').hide()
  if url && $(window).scrollTop() > $(document).height() - $(window).height() - 150
    $('.loader').show()
    $.getScript url, ->
      $(window).on 'scroll', onEndless
  else
    $(window).on 'scroll', onEndless

$(window).on 'scroll', onEndless
  
$(window).scroll()
Avatar

I am using Morris chart. How do i reverse the values on the Y axis.

I am tracking ranks hence lower the better.

http://www.siterankhistory.com

Avatar

Where you able to find a solution to this? I'm facing the same problem.

Avatar

I just had this same issue. My problem was that I was searching for row["id"] but my spreadsheet had "ID" instead.

Avatar

Figured it out! Assets were not compiling correctly. Ignore my previous comment, although this showed me how hard this was to debug. Thanks for the great learning resources Ryan.

Avatar

If you're using chrome you don't actually need to open a different browser to test, you can just hit cmd+shift+n to open a new incognito window and log in as your test user there.

Avatar

Any advice about using Doorkeeper with Active Model Serializers as shown in episode #409?

Avatar

I think you want to do this

ruby
    def destroy
      @comment = Comment.find(params[:id])
      @commentable = @comment.commentable
        if @comment.destroy
          respond_to do |format|
            format.html { redirect_to @commentable, notice: "Comment deleted."  }
          end
        end
     end
     

I might be wrong.

Avatar

Just to clarify Turbolinks will be included by default in a new Gemfile generated with Rails 4 it is not built into the framework

Avatar

I posted a possible solution for that on stackoverflow

Avatar

If I am using paperclip and have an upload option in first step.
Will the attachment be persistent in session/rack or I need to use some temporary table/model to store that file before the complete form is submitted ?

Avatar

Try it:
def data
users.map do |user|
[
link_to(user.name, user),
h(user.email),
link_to("delete", user, method: :delete, data: { confirm: 'Are you sure?' }),
"#{check_box_tag('user[]', user.id)}"
]
end
end

Avatar

You can tag it as 'slow' and just run it on CI.

Avatar

I followed the last episode as well as this one, but I cannot lighten up the header by overriding the @navbar* variables as described. I am able to override @linkColor, but I'm not able to override the other variables. Everything worked fine up to that step, starting from the beginning of the last episode. Any suggestions?

Avatar

Corey - could you go into a little more detail on the proxy object? I'm looking to do something along the lines of letting users (admins) make new forms for the public to submit data to. Following this screen cast I've got it implemented but I'm a Ruby and RoR n00bie.

I've the situation where what data I need to collect is custom per situation, so hard coding Models isn't an option so I am using the Admin's building of a collection of form fields and then dynamically building a model that is then used to make the form for the public and store the data in Mongodb. I've read a bit on factory design patterns and template patterns but I've not yet tried to apply this within rails to even see if it would work.