RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Thanks for the screencast, Ryan! For a small project, this is much better than a full-blown authentication system like Devise.

I'm working on an app where I have a Customer model that should just store basic contact information and may optionally include a login with username and password. Is there any way to use has_secure_password if a password is set yet also allow for a Customer to be created without a password?

Avatar

oops, wrong screen cast, I meant to put this in 3.1 Auth.

Avatar

This is what I cam up with for the time being...

ruby
def create
            t_params = params.dup

              if params["format"] == "json"
                    t_params.delete("action")
                t_params.delete("controller")
                t_params.delete("format")
                t_params.delete("user")

                @user = User.new(t_params)
              else
                @user = User.new(t_params[:user])
              end

            respond_to do |format|
                    if @user.save
                            format.html { redirect_to root_url, :notice => "Signed up!" }
                                format.json { render json: @user, status: :created, location: @user }
                    else
                            format.html { render action: "new" }
                            format.json { render json: @user.errors, status: :unprocessable_entity }
                    end
            end
        end
Avatar

in case your struggling the beaded should be 'based';

what I want to know is if no image is uploaded for a post can you default to the image of the category that the post belongs to?

Avatar

I have a blog application and would like to default to an image beaded on the category association of the post if no image is uploaded. Is this possible?

Avatar

Hey guys, I modified this a little bit so that it could be used with Twitter's bootstrap framework. It allows for the TH tag to be clickable instead of making the text a link, check it out!

https://gist.github.com/1392144

Avatar

Did you find any solutions? I've notice same thing in my site, and also even in RailsCasts site, in FF as well as in Chrome Linux versions...

Avatar

Great Tutorial now only problem I have with this ( After upgrading to rails 3.1)

Missing template messages/create
I cloned the rails casts and setup the 260 after version in a clean directory.

create.js.erb is also there,
anyone an idea how to get this to work with 3.1? Thx!

Avatar

This is what I cam up with for the time being...

ruby
def create
            t_params = params.dup

              if params["format"] == "json"
                    t_params.delete("action")
                t_params.delete("controller")
                t_params.delete("format")
                t_params.delete("user")

                @user = User.new(t_params)
              else
                @user = User.new(t_params[:user])
              end

            respond_to do |format|
                    if @user.save
                            format.html { redirect_to root_url, :notice => "Signed up!" }
                                format.json { render json: @user, status: :created, location: @user }
                    else
                            format.html { render action: "new" }
                            format.json { render json: @user.errors, status: :unprocessable_entity }
                    end
            end
        end
Avatar

Is it possible to do a post to create a new user via json?

I've added validates_presence_of :email, :on => :create

I'm trying.

POST /users.json HTTP/1.1
Content-Type: application/json

{
"email": "myuser@useremail.com",
"password": "1234",
"password_confirmation": "1234"
}

It picks up the email field but not the others. Is it even possible to do a post like this with the password_digest system?

Avatar

For some season I am getting:

Missing partial properties/property with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths "C:/rails-code/prevu/app/views", "C:/Ruby192/lib/ruby/gems/1.9.1/gems/sorcery-0.7.4/app/views"
Avatar

Just stumbled upon the solution: get rid of webrat from your Gemfile.

Fixed many other testing issues too.

Avatar

Great cast...I'm new to rails so this has been a big help!

I've had one issue -- in my model, I have some dates (by design) that do not have an entry. But the array seems to create a date key with 0 value for every day in the time period. I only want to graph days that have table entries - ex: 10 days out of the 3 weeks.

Currently the highcharts will graphs the no entry days as $0...this might be okay for this specific sale app, but not useful for other apps.

Any ideas?

Avatar

Won't the browser just cache mercury.js? If so is it still necessary to stop it from loading on every request?

Avatar

Hello all,

I have one question. Method "destroy" belongs to any rails model, so if I call it means that I violate the MVC concepts. The right way would be remove the model from the controller. Am I wrong?

PD: sorry, my English isn't that good.

Thanks.

Avatar

I agree, gmaps4rails is a great gem. Try it first if you need to handle maps in your app.

Avatar

I am sure you already know this, but others may not. You can combine the git submodule init and git submodule update commands and just run: git submodule update --init. You can also just use the --recursive flag on the initial clone and it will init and update the submodules automatically.

Avatar

Github has explicit instructions on how to do this right in the pull request.

Avatar

Would love something like this where mongoid is used :)

Avatar

When i try to install mercury , and run rake mercury_engine:install:migrations

i get the following error

rake aborted!
Don't know how to build task 'railties:install:migrations'

any idea why this happens ?

Avatar

Nice screencast!

But I believe that screencasts that help people to grow the community like creating ruby gems should not be PRO screencasts.

Avatar

Great episode, just like the 299 before :).

Congratulations Ryan! I'm not sure whether the Rails/Ruby community realizes how many new developers were recruited alone by your top quality screencasts.

Keep on the fantastic work! The $9 I pay for RailsCasts Pro is probably the only monthly expense that makes me smile everytime I get the receipt.

To another 300 episodes
Sebastian

Avatar

Everything seems to be working just fine for me except one thing. Every time I save a spec file and those tests get run, the time that RSpec says they finished in is actually the amount of time that Guard has been running. So the time in seconds just keeps getting bigger. Has anyone else encountered this? Any ideas how to fix it?

I'm using Ruby 1.8.7, Rails 3.1, and everything else is pretty much the same as the screencast.

Avatar

Awesome, you're great, I love your screencasts :)

Avatar

I ended up fixing this by rolling back my migrations and then migrating again. Anyone know why this would be necessary??

Avatar

Can "my_sort_field" be a virtual attributes? I tried but no success. Do you know the way to implement this?

Avatar

Ryan,

This is really awesome, thanks for the screencast. Testing JS functionality is a huge improvement for me -- however, it seems to come at a pretty steep speed cost.

Is there a way to configure the specs (or more specifically, to configure Guard) to NOT run JS specs by default? I would prefer to only run those when I run the entire test suite, or if I've "enabled" js testing somehow.

Because guard calls the request spec whenever I do any work on the controller or other request specs, and because the request spec now runs selenium to test in firefox, my guard setup is now painfully slow when I'm working on anything that has associated js tests...

Avatar

Thanks Ryan for this.

A follow up question: I know you usually create a topic branch for each pull request. However, once the request is accepted and what not, what do you do with said branch? Delete it, continue to branch off of it, or some sort of rebase?

Avatar

Ryan, you are awesome. Hopefully this will be an amazing gift to open source project maintainers for the holidays-- you get a contribution, and you get a contribution, and you get a contribution!!!

For anyone looking for projects to contribute to, here are some projects that I know would love help:

Avatar

Alternatively, you could include the application javascripts in the admin package and only serve that on admin pages.

Avatar

Hey Ryan I am follower of railscasts it has helped me out of trouble and understanding the way things work thanks alot. The new layout looks awesome.

I have a bit of a problem with coffiescript:
My gem file:

ruby
gem 'rails', '3.1.1'

platforms :jruby do
  gem "activerecord-jdbc-adapter", "~> 1.2.0"
  gem "jdbc-mysql", "~> 5.1.13"
  #gem "jruby-openssl"
end

platforms :ruby do
  gem 'activerecord-sqlserver-adapter'
  gem 'ruby-odbc'
end
group :assets do
  gem 'sass-rails',   '~> 3.1.4'
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'
end

#### Styling
gem 'jquery-rails'
gem "haml-rails", "~> 0.3.4"
gem "haml", "~> 3.1.3"
gem "inherited_resources"
gem "formtastic", "~> 1.2.4"

In the application layout:

haml
  = javascript_include_tag  "application"

In my application.js:

javascript
  //= require jquery
  //= require jquery_ujs
  //= require_tree .

In my games.js.coffie:

javascript
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
alert "I knew it!"

My application runs but as soon as I go to the browser I get the following error:
unexpected token at '"ok","\n alert(\"I knew it!\");\n"]

If I take out the //= require_tree . the application works.
Can you help me if you want more info on the application here is the link to it https://github.com/Gerhardk/Battleships its a game which I am writing to get the feel of the new Rails 3.1.1 way of doing things

Thanks Gerhard

Avatar

Ryan,

It looks like you blog-after directory in the source code is not updated with the format_url method.

Avatar

Excellent cast. Here is a link to the Engine Yard Blog mentioned in the screen cast.

Avatar

Thank you , didn't have time to investigate this github feature myself.

P.S.
IMO, it would be even greater idea if you would allow to participate in competition those who create new gems (like in #301) , not only those who create pull requests.

Avatar

Thanks Ryan. This is the first time I have seen any step-by-step tutorial on how to do it. Most documentation just says, fork & pull, and it's easy.

On the flip side, do you plan to do a video on how to accept and integrate pull requests for open source contributions?

Avatar

I thought 'facets', while nicely rubyish, was a confusing term until I mapped it (mentally for now) to 'filter_groups'. Always looking for good names to aid obviousity ;)

Avatar

Can be interesting, but I'm really sad that the railscasts didn't really speak about rails anymore. Free railscasts continue, but in fact it's no longer free to get interesting content.

I don't want to criticize, and I don't have the right to, you did an awesome work during few years and it's normal to want to rentabilise it, I just want to make my point, that's all.

EDIT : This comment more apply in general to all episodes since the pro option, this episode was quiet interesting

Avatar

As it is now, metrical seems not to work anymore, I get following message when installing:

bash
~/Dokumente/sources/ruby/1.9.2/rails3.1/webworld:feature/modelspec$ gem install metrical
ERROR:  While executing gem ... (Gem::DependencyError)
    Unable to resolve dependencies: metrical requires main (~> 4.6.0); metric_fu requires chronic (~> 0.3.0); churn requires chronic (= 0.6.4), main (= 4.7.7), main (>= 0), chronic (>= 0.2.3)

Are there alternatives to metrical?

Avatar

Found a way to get this working using the stache gem.

Avatar

Useless to anyone outside of the US :(

I was very excited about this, but when I contacted Stripe, they said they will let me know when they will be available in Europe (England in my case) but I'm not holding my breath.

Avatar

THANKS FOR THE TUTORIAL.

I am getting errors below on ruby192 and rails 3.1.0 when I run rails g spree:site

my gemfile contains gem "spree" instead of latest version because of dependency problem.

Also command does not modify assets css like in this tutorial and does not copy a lot of migration files.

ANY IDEAS ABOUT THOSE ISSUES THANKS!

ruby
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from <top (required)> at /Users/ghaydarov/Desktop/spree/config/application.rb:7)
[DEPRECATION WARNING] Nested I18n namespace lookup under "activerecord.attributes.checkout" is no longer supported
      create  lib/spree_site.rb
      remove  public/index.html
      append  public/robots.txt
      append  db/seeds.rb
Avatar

Just stumbled across this awesome tutorial. Combined this with my ActiveAdmin dashboard for some nice results. :)

Avatar

This was very interesting Ryan, thank you. I hope to see more screencasts on Rails' internals in the future!

Avatar

Good point! I've put a commit into docrails, the Rails documentation repository, to add a link to this guide. I've also tried to help tidy up the Initialization guide a little, as it's quite rough around the edges. It's community-maintained, so anyone else able to help should go for it.

Avatar

why in this episode "/auth/twitter" suddenly redirects to twitter authentication page? its neither in routes file nor there is such an action on the controller, please explain, im struggling to understand.

Avatar

Make sure you re-index and try using string again because I know for decimal you have to use float and for date you have to use time.