RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Thanks for sharing this piece of info about default new ids created by Rails.

Avatar

Sadly, I am getting ActiveModel::ForbiddenAttributesError when I try to use this recipe in Rails 4. Any idea how to update it for Rails 4?

Avatar

do you have the gem in the assets group? Rails 4 has done away with the assets group so try removing that group and running bundle install again.

Avatar

Hi Ryan,

I liked this episode but would really like to see how one would approach the has_many model situation and nested forms with angularJs. I cant find anything that can help me save the attributes from one model plus the nested model.

Avatar

Another awesome cast - I love how in the end there are no queries!

Avatar

I found a replacement for request.path[1..-1] posted by Jeroen Rosenberg:

ruby
status_code = ActionDispatch::ExceptionWrapper.new(env, @exception).status_code
Avatar

I have a site using pg_search and GIN indexes per this screencast. Recently I changed the pg_search_scope on a model to use the "simple" dictionary instead of "english". So then, do I need to write a new migration to update the GIN indexes as well since those indexes refer to_tsvector "english"?

Simplified example below.

class ChangeIndexesOnClients < ActiveRecord::Migration
  def up
    execute "drop index clients_name" 
    execute "create index clients_name on clients using gin(to_tsvector('simple', name))"
  end
  
  def down
    execute "drop index clients_name"
    execute "create index clients_name on clients using gin(to_tsvector('english', name))"
  end
end
Avatar

+1, works in Firefox, but not in IE or Chrome.

Avatar

Yes I was having this issue. I got around it with the following:

JavaScript
jQuery(window).on('mercury:saved', function() {
   window.location.href = window.location.href.replace(/\/editor\//i, '/');                
});
Avatar

Meteor currently is heavily reliant on mongodb because it uses minimongo on the front end. I believe there are a few groups looking to implement a Postgres version on the backend. I think Mongo makes Meteor better because it forces you to design your applications with speed in mind.

Avatar

I renamed my :allow and :allow_params matchers to :permit and :permit_params to get past this error.

Here's my spec/support/matchers.rb file.

And my specs look like this (should permit(... instead of should allow(...)

ruby
it "allows anything" do
  should permit(:any, :thing)
  should permit_param(:any, :thing)
end
Avatar

But how do you render something in full JS ? Using render_to_string and sending a JSON ? An other solution or example ?

Avatar

Has anyone gotten the S3 direct upload version at the end with Rails 4? The uploading works, but the page doesn't get updated without a refresh, and I don't see the progress bars.

Perhaps it has something to do with Turbolinks?

Any help would be much appreciated.

Avatar

I'm getting a 500 error on my heroku site and a 401 error on my localhost. My site links to Twitter and allows log ins but returns a "Could not authenticate you from Twitter because "Invalid credentials"". I am 100% sure the keys are correct. Any advice?

Avatar

did you set environment varilables for TWITTER_SECRET and TWIITTER_KEY based on what you set up on the dev.twitter.com site?

Avatar

Seems like he's doing fine now. Railscasts has become a great service. Great job Ryan.

Avatar

Wow, thanks!
I tried to figure out what's wrong with my headers for 20 mins before I decided to check the internets. You saved my day!

Avatar

If you're having problems with some jQueries you can try the jQuery-Turbolinks gem: https://github.com/kossnocorp/jquery.turbolinks/

Avatar

It seems for some people subl-handler doesn’t work as expected. Here’s my two cents: https://github.com/exalted/sublimetext-launcher

Avatar

Sorry for the content-free post but just had to say, that was an amazing episode, thank you Ryan :)

Avatar

Are you planning on doing a video that shows how to both use the User authentication as well as a separate Admin Auth that can manage all the Users that exist within the database?

Avatar

Thank you for awesome screencast. I got inspired and wrote little more enhanced version of this (for example fallback to generic error message layout, and hiding 500 error messages in production): https://github.com/sheerun/rails4-bootstrap/commit/5c2df5a108ad204bc407183b959bb355ff5ed53d

Avatar

How can I get cancan to lookup activerecords when I'm using the has_permalink gem?

If I access a url by it's has_permalink ID, example - articles/my-article-name/edit I get an error saying it can't find an article with that ID but when I access the article using the ID number it works fine.

Avatar

Is this safe to put these credentials on dom:

html
<input name="policy" type="hidden" value="XXX">
<input name="signature" type="hidden" value="YYY">
<input name="AWSAccessKeyId" type="hidden" value="ZZZ">
Avatar

If you are having issues getting started with Rubber take a look at this post. I had a few issues getting started and this is how I resolved them.

http://www.flaskofespresso.com/2013/08/rails-rubber-aws-ec2-deployment-issues-with-groups-and-rules/

Avatar

There is a typo in the ASCIIcast; In the code block for adding the default url options it's specified as "- { host" but should be "= { host".

Avatar

I'm running postgresl 9.2.1 on Mac OS X, installed by homebrew and Rails 3.2.12

The postrgresql lib directory has unaccent.so

But it is not installed by default and Ryan's migration did not seem to do anything.

What worked for me was:

bash
$ rails db
my_db=# create extension unaccent;
my_db=# \dx
                         List of installed extensions
   Name   | Version |   Schema   |                 Description
----------+---------+------------+---------------------------------------------
 plpgsql  | 1.0     | pg_catalog | PL/pgSQL procedural language
 unaccent | 1.0     | public     | text search dictionary that removes accents
Avatar

Good screencast. However, one thing left out that was mentioned in the original ones is the :reject_if => :all_blank in the model.

Avatar

Can you tell us what an alternative would be?

Avatar

Some notes on SignupForm. Each model has its own validations. When I want to use the same validations I should copy-past them?

Avatar

Yes there is a way, I recommend only to use in development, it has some drawbacks.

ruby
Test::Application.configure do
  ...
  config.cache_classes = false
  config.eager_load = false
  config.middleware.delete Rack::Lock
end
Avatar

Hi, I'm encountering a redirect loop when logging in. Has anyone encountered this before? I'm using Rails 4 BTW. Thanks!

Avatar

Just to clarify for anyone else reading this, &crarr; is the HTML entity for carriage return. The line in your Gemfile should be:

gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i
Avatar

People, I am having a little problem, I think that is because de turbolinks, when I click in the new task link more than one form is showed to me, anyone can help me? when i disable turbolink, everything it's OK

Avatar

Hi there - how do you specify the authentication to use in your "# use http_basic_authentication" ?

I.e. when inside the JSON case, what is the next step to authorise the request? Currently I'm really struggling getting a JSON API via HTTP basic auth

Avatar

First of all: Great episode again, Ryan - thanks!

We had the idea to implement a notification pushing mechanism based on the ActionController::Live functionalities. Basically everything works fine from the functional perspective.
But: Am I the only one who doesn't want to accept that you have to restart your development web server (Puma) every time you change something in your code?

For me this is highly uncomfortable. Does anybody else encounters the same problem? Maybe there's a solution for this somewhere out there that I can't get hold of right now?

Avatar

I needed this as well. I've managed to make it work (with Facebook anyway - but it should be trivial to support other providers as well). Code at: https://gist.github.com/troelskn/6240837

Note that this is for Rails 4.

Avatar

If you are on Rails 4 and get a cryptic error message along the lines of ArgumentError in Devise::RegistrationsController#new wrong number of arguments (2 for 1), just remove the without_protection key in user.rb. Source: http://stackoverflow.com/questions/17105112/argumenterror-in-deviseregistrationscontrollernew-wrong-number-of-arguments

Avatar

Hi Ryan,

using the pubsub approach within the ActionController::Live we ended up with a lot of Threads that are never closed. I think Redis subscribe and psubscribe are blocking the created Thread and stream.close will never be called, will check this soon.

What we've noticed gets even worse with new visitor and each page reload we ended up with a new Thread. At the end we had many Threads sleeping consuming all available Threads for puma.

There is also an issue at github addressing this: https://github.com/rails/rails/issues/10989#issuecomment-21305888

Avatar

I can get the sample data working in my Rails app (3.2.14), but when I try with real data, the chart doesn't show up. It appears my JSON string has an extra level of nesting in it, where it's {model_name: {properties}}, you can see my code and an example in my Gist. Any help is greatly appreciated!

Avatar

Thanks for the screencast. I'm just wondering...is there a simple way to implement this while using devise? Right now, I'm thinking that I'd have to kind of hack the out my own create method in the UserRegistrationController that devise comes with.

Avatar

i'm getting "exit status 1" for jruby

bash
Available Commands: [waiting] [crashed] [ready]
zeus destroy (alias: d)
zeus generate (alias: g)
zeus rake
zeus server (alias: s)
zeus console (alias: c)
zeus dbconsole
zeus runner (alias: r)
zeus cucumber
zeus test (alias: rspec, testrb)
exit status 1

but on a high note works great for ruby-1.9.3

Avatar

Hi all. Question:

I have my root to "entries#index"

When I paginate entries with <%= paginate @entries %> visiting the root (/), the pages links goes to /entries?page=N instead to root as /?page=N.

How would I tell kaminari to do that?

Thanks!