RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Given the changes with Redcarpet, I was not able to get the steps in this Railscast to work. But, I used it to help me understand what I was looking at in figuring out what to do next. I got Redcarpet working with my Rails 4, RC1 blog. If you'd like steps, you can peek at it here:

http://www.hamcois.com/articles/4

Avatar

To get the latest Rails config settings there's no need to copy/paste from another project just run rake rails:update.

Avatar

If the only reason they're not switching is because they already have an account, then they're probably not that grumbly. We're talking about subtle unconscious cues that influence the stats in otherwise unnoticeable ways here, not torturing users and tying a lease around their neck.

Avatar

I struggled a bit, while converting my rails-api app to use ActiveModelSerializer, on how to modify my specs to check for the JSON coming back (without doing something ugly like hard coding them).

Thanks to Ryan for this RailsCast - it got me to take a look at active_model_serializer, as shown at the end of the asciicast, and using that in my tests simplified things.

You can see my conversion to active_model_serializer in this commit, including my request spec changes.

Avatar

I have really gotten a ton out of Ryan's work. It's helped me immensely learning Rails and I still know nothing.

I put together a small instructional guide for those who want to use dataTables with Twitter Bootstrap. My environment is Rails 4, RC1.

Anyway, hope this helps. As it's long, I'll link it, but I can post it here if that's more appropriate.

http://www.hamcois.com/articles/3

Avatar

He gave the example of what this would look like with Capistrano. What if I just want to run it locally to test it out? Also, how do you deploy it to the server if you are not using Capistrano?

Avatar

Seems that you've answered my question ... Thanks !

Now you can watch this RailsCast for the answer ;)

Avatar

Processing by PagesController#show as
Parameters: {"id"=>"favicon"}
Page Load (0.2ms) SELECT "pages".* FROM "pages" WHERE "pages"."permalink" = 'favicon' LIMIT 1

Can someone tell me why the get ':id', to: 'pages#show', as: :page route in my route.rb file is passing favicon as an id parameter?

Avatar

Thanks for this Ryan.
I have a problem, every chart that I want to draw will be in "Line charts".
even when I put
chart: {
renderTo: 'container1',
type: 'bar'
},
it will in "Line charts" not in 'bar'.

thanks a lot

Avatar

Hello, could you please asciicastize it? Thanks! :-)

Avatar

Thanks Florent. Exactly what I was looking for. :)

Avatar

I can't seem to be able to access "current_user" in the Serializer.

Error:
undefined local variable or method `current_user' for #PostSerializer:0x5bcd9af2

The current_user is available in my controllers and views. (jRuby on Rails with Devise)

Does anyone have an idea why this might be?

Avatar

I am using windows on my development machine ,,,any one having experience on adding ssl while developing on windows ,,please help me ..thanks

Avatar

Is the inaccessible current_user problem still true ?
the Purpose section of AMS readme says
"Serializers know about both a model and the current_user" so...

(installing the gem now to try it out though !)

Thanks Ryan !

Avatar

Hi, when I click the reset password button its giving me a validation error saying Validation failed: Password can't be blank?
Any help? I'm quite new to this?

Avatar

Anyone know how to add stopping/starting the script/mailman_server to Rubber?

Avatar

This doesn't work for me. I still get a 401. I also tried http://127.0.0.1:3000/auth/twitter/callback to no avail.

Avatar

Hi I just want to ask on how to configure live email account by Microsoft on

My Gmail config that is working
config/environments/development.rb
config.action_mailer.default_url_options = { host: "example.com" }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address: "smtp.gmail.com",
  port: 587,
  domain: "localhost",
  authentication: "plain",
  enable_starttls_auto: true,
  user_name: ENV["GMAIL_USERNAME"],
  password: ENV["GMAIL_PASSWORD"]
}

how about the live email account configuration that is similar with gmail smtp configuration?
example
username: myemail@live.com
password: SamplePassword

Thanks!

Avatar

Great post! Thanks, there's quite a lot to see.

Avatar

confirmed - got my invite today! let's play...

Avatar

I eventually went with something like this. Works well for me.

ruby
  def create_schema()
    original_search_path = connection.schema_search_path
    connection.execute("create schema tennant#{id}")
    connection.schema_search_path = "tennant#{id},public"
    structure_sql = open("#{Rails.root}/db/structure.sql", 'r').read
    structure_sql = structure_sql.gsub("SET search_path = public, pg_catalog;", "") # Remove line from SQL dump file
    connection.execute(structure_sql)
    connection.execute("drop table my_table")
    ensure
      return connection.schema_search_path = original_search_path
  end
Avatar

Great stuff.
What about the sqlite :memory: database ? I have been using this since months for my tests, just to speed up the database transactions without having to change the specs. Not sure how big the gain is in the current rails but it was a big improvement once.

Avatar

Thanks for the cast Ryan you spelt it well as usual. But somehow I share that kind of disappointment with Cyle. It is not if anything were missing, it is just there is no big Wow as there has been before with major releases. Probably a good sign for maturity...

Avatar

I did not know about Railsdiff. It's fantastic.

Avatar

Great episode, actually haven't seen it until it was referenced in episode #415.

However, if rails 4's default behavior will now rely on strong parameters instead of attr_accessible, I suppose this episode will become pretty essential rails 4 users. Will you be making this episode public, or will it remain a pro episode?

Avatar

you misspelled omniauth ... you wrote 'ominauth'

user = User.from_omniauth(env["ominauth.auth"])

Avatar

Here's a sudo template helper method to keep your code... DRY

ruby
def template_sudo(from, to)
  erb = File.read(File.expand_path("../templates/#{from}", __FILE__))
  put_sudo ERB.new(erb).result(binding), to
end

def put_sudo(data, to)
  filename = File.basename(to)
  to_directory = File.dirname(to)
  put data, "/tmp/#{filename}"
  run "#{sudo} mv /tmp/#{filename} #{to_directory}"
end

Put it in config/recipes/base.rb

Avatar

I noticed 2 areas of improvement:

Rails 4 syntax is less verbose and more intuitive when writing queries.

Rails 4 has a heavy emphasis on security.

There are several more features covered in various blogs and podcasts.

To summarize, Rails 4 "feels" more mature.

I took a huge commercial app and was able to upgrade it from Rails 3.2.13 to Rails 4.0.0.rc1 in half a day. Having the test suite in place made the transition process go smoothly. There are a few popular gems that we use that are not Rails 4 ready so releasing this upgraded app to production will have to wait.

Avatar

AWESOME article ...worked like a charm except one change.

If you installed RoR using RailsInstaled make this SSL fix.
https://gist.github.com/fnichol/867550

I used the same pattern to allow sign in with LinkedIn

Use this gem "omniauth-linkedin-oauth2"

and use this provider :
config.omniauth :linkedin_oauth2, ENV["LINKEDIN_KEY"], ENV["LINKEDIN_SECRET"]

Also you can get the email address from the session so that the user will be automatically created.

In user.rb model class self.from_omniauth method add this line
user.email = auth.info.email

Avatar

Thanks for these non-so-intuitive step :)

Avatar

awesome, was just wondering that.

Avatar

I agree w/ @kikorb. The scary thing is what happens when a relative noob (like myself) tries this. A checklist might be one way of looking for all the gotchas.

Avatar

Thanks Ryan.

There is no need to say how many unproductive hours and nightmares you are avoiding us with episodes like this one.

Avatar

Are there any big advantages to upgrading to Rails 4 - I'm a little familiar with some of the new features that are offered and none of them sound appealing to me at the moment.

Avatar

You can also rename update_attributes to update

Avatar

Very nice summary!

You can generate a new secret_key_base by running rake secret.

If you're interested in some more details about Rails 4 (and deeper dives on some of the topics shown), I'm writing an e-book: http://upgradingtorails4.com/

Avatar

How unfortunate that ActiveModelSerializers are nothing more than views without templates. If they were coupled with deserializers, that would be a real difference. Recently I'm trying Roar which is basically the same thing, but works in both directions.

Avatar

Yeah, web APIs are (or should be) sticklers for proper status codes, but any ol' HTML browser can infer a lot from the status code too. Whether or not to use the URL when auto-completing an address for the user, for instance. It's annoying to have the browser remember a URL for an error page, only because that page accidentally sent a 200 OK

Avatar

Hi all,

It seems like the Paypal website is now working differently.
Is there a revisited version of this tutorial ?

Thx !

Avatar

Yeah, I agree. It's a great introductory topic. But there are lots of things to cover.

  • differences between .gitignore, .git/info/exclude, $HOME/.gitignore
  • useful but not that obvious Git commands (blame, bisect, rebase)
  • git submodules (or maybe it's to Gittish?)
  • example of good workflow, of course that only true workflow, with rebases instead of "merge master into …" :P
  • text editor integrations

So either a good topic for a long episode or a series of two. Or maybe I've written too many git-specific things?

Avatar

Cool video. Wanted to try out 4.0 (aka First)