RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

You would be able to see them, yes. That's why it's best to secure your controller actions as well as your views to ensure that, even if someone disabled styling or if they typed in the path to those actions explicitly, they would be unable to access that functionality.

I prefer not hiding things with CSS, myself; using JavaScript instead to add those dynamic elements to the DOM after the cached page has loaded.

Avatar

Nice episode, but I have a doubt. If I have the Edit|Destroy links available at all times, but hidden using CSS, doesn't it mean that if I disable CSS from my browser I'll be able to "at as an admin"? (I mean, see the full page, including those links and all the other hidden "actions").

Avatar

i really can't see the benefits of using this kind of libraries inside rails. i mean, if i had to build something from scratch and have to structure the app, so maybe there something like backbone.js will be helpfull.

but i don't see the need of backbone.js inside rails since ror is already well structured and all the JS stuff can be fully served with jquery (or similar)...in fact, what i see here is backbone is complicating the "fun" of programming on rails.

...do im right? or i'm missing something? please, somebody help me to understand...

Avatar

Hey! Thanks for the link to Sencha Designer 2. I have read a lot about Sencha Touch 2 in the last month. It looks very cool!

Avatar

The entire form can be given a class, for instance to use twitter's bootstrap, through the following:

ruby
def boot_form_for(object, options={}, &block)
    options[:builder] = Bootstrapped
    options[:html] = { :class => "form-horizontal" }
    form_for(object, options, &block)
end
Avatar

Thats's neat. I am trying to re-code some unfinished application using RABL.

Avatar

Nevermind, I guess I found the answer to my problem. Here's how I tackled it:

registrations_controller.rb
def build_resource(*args)
  super
  if session["devise.omniauth"]
    @user.apply_omniauth(session["devise.omniauth"])
    session["devise.omniauth"] = nil
  end
end

You should change that session info to nil not after the creation action but immediately after building the resource.

Avatar

I can use facebook omniauth locally. Perhaps your problem lies with your ssl certificate? I had that problem, you can see it's resolution here

Now, I have a question of my own. Using this method described by rbates, if a user successfully authenticates using Twitter which doesn't provide an email, he is taken to the signup page to complete the registration process. Now, if he doesn't complete the registration process, the @user remains in the session (I don't know how) so the next time you try to register, you'll have that authentication method attached to the created user, which could be a completely different user. How do I solve this? Basically, all I need to do is delete the user if I leave the signup page so how do I do that?

Avatar

Braintree looks way better than say authorize.net, but Stripe has these advantages:
- Developer friendly, less headaches
- No monthly fees
- Very easy setup

Avatar

@1. I was wondering the same. Values like that are prone to change so it's best to have them in some sort of global variable. I had always used the approach:

Stripe.setPublishableKey('<%= STRIPE_PUBLIC_KEY %>')

I see one advantage to the meta tag version in that you don't have to give your coffeescript file an .erb extension. This can confuse certain text editors. Other than that, I can't figure out why he would have used a meta tag.

Avatar

Thanks Ryan for the episode.

If you will be covering KnockoutJS (which is currently my preference after evaluating most of the frameworks) then you may want to take a look at knockout-rails gem.

Simple screencast that demos validations part of it:
http://blog.approache.com/2011/12/knockoutjs-validations-video.html

(it went into Ruby5, so seems like people liked it).

Cheers.

Avatar

Thanks! In my case I did something similar to the following:

locals: { show_price: defined?(show_price) ? show_price : false }

Avatar

Just a suggestion to everyone here:

This tutorial is very much geared towards a particular way of using backbone on rails. (Understandable since this is a railscast)

I would suggest learning backbone yourself as a standalone html and js served out of public and communicating with your restful resources first, that way you can learn more about things like modularizing your app vs namespacing etc.

learn backbone, then backbone on rails.

Avatar

I really liked this railscast, but i'm wondering if can be the backbone/eco part easly separated from rails project and compiled to make an external client?

Avatar

Woah, backbone.js is like a completely different framework from rails.

Following this tutorial felt like going through a Python tutorial, I don't understand anything. hahah :D

I need to look up how backbone.js work or what its purpose is because I don't know anything about it.

Avatar

first off: I am using rails 2.1.1 and ruby 1.8.7. I have the gem installed so I'm pretty sure that is all setup.

But here is my issue:

  1. I am building an API, and have defined specific routes for each API function. an example of one is:

map.ipad_push '/api/ipad/v1/push/user/:user_id.:format', :controller => 'api', :action => 'push'

I have my api_controller.rb, and an action defined in it called "push"

in views/api i have file push.json.rabl

But when I try to view the json, I get the "Missing template api/push.json.erb in view path /Users/pwgustafson/Desktop/HitFix/hitfix2/app/views"

I was able to get this working in another rails 3 app, so I'm curious if there might be some basic thing I'm doing wrong to get this working.

Avatar

Not sure why but each day lists out the all the articles for me instead of just the ones for that day. Any suggestions?

day_method is correct too (I'm using :due_date and it has a datatype as date).

Any idea what's wrong?

Avatar

I'm seeing this same issue. Only the original slug is saved in history. I had assumed that all past slugs would be recorded. Seems less than ideal.

Avatar

Yeah, really check your CoffeeScript formatting / indentation. I had a couple of those. I had to turn on soft tabs.

Avatar

I think it would be worth to mention ExtJS 4 / Sencha Touch 2. It is more comprehensive and powerful than Backbone. It uses similar approach - client side MVC but Sencha have also validators, a lot of widgets and the killer app - Sencha Designer 2, graphics IDE for fast building the whole application (see: http://vimeo.com/36420727) In all such solutions Rails can be narrowed to be just RESTfull server...

Avatar

Very nice Episode!
It would be nice if you could easily customize the xml output with CDATA for special characters :)

Avatar

This is exactly thing I need! Thanks for your reply.

Avatar

Great episode, but not really useful in my current project. I would love an episode about fragment caching instead!

Avatar

I wonder why no one mentions the command rake rails:update - even the Rails 3.2 release notes don't.

Avatar

I got the same error and I have been searching for the answer from last three days.. It's jst freaking me out.. Is there a real solution to this error??

Avatar

You can do a lot with noscript tags and to make sure pages behind js links are crawled, you can include their urls in a sitemap and submit it to google, etc..

Avatar

Backbone is more mature - there are lots of online videos, blog posts, and example apps for BB - not so much for Ember. Right now Ember also lacks support for routing and persistence.

Avatar

I get an exception thrown when I start dealing with the routers. I'm not going to ruin the forum by pasting my (exhaustively long) trace in here, but I am getting the following message: Error: Parse error on line 7: Unexpected 'TERMINATOR'. Can anyone point me in the right direction? This seems like a CoffeeScript thing that I'm just lost on. Thanks in advance!

Avatar

VLC.. or download the mp4.. or click WebM in any browser that supports it...

Avatar

Being forced to install a bloated (120+m) DivX player just to watch my beloved RailsCasts is not making me happy. It's probably not your doing, but please pass along the disgruntlement of at least one (and probably many more) viewers about this HUGE step backward by Sublime

Avatar

One thing i would REALLY like to know: With all these really nice client side mvc frameworks popping up, what the heck do we do about making our app's content searchable/crawlable? I really have not seen much insight into this problem.

Since most (all?) of the web crawlers don't use javascript, do we REALLY have to design separate pages for the spiders?

Avatar

I have a question about the history feature.

I implemented it on one of my models, but it seems that it only keeps a history of the original slug, even after every edit. Is this how it's supposed to work?

Say I have a title of "Hello World" which generates a slug "hello-world"

If I edit this to "Hello World 2" and then eventually to "Hello World 3", am I supposed to have all 3 history changes, or just the original?

hello-world - original works
hello-world-2 - doesn't work <-- does this not get stored?
hello-world-3 - latest works

Thanks!

Avatar

In case anyone wants the coffeescript. Note that I kept the .submit bit in addition to .keyup in case the user hits submit.

products.js.coffee
jQuery ->
  # Ajax sorting and pagination on click
  $('#products td.sortable a, #products .pagination a').live('click', ->
    $.getScript(this.href)
    false
  )
  # Ajax search on submit
  $('#products_search').submit( ->
    $.get(this.action, $(this).serialize(), null, 'script')
    false
  )
  # Ajax search on keyup
  $('#products_search input').keyup( ->
    $.get($("#products_search").attr("action"), $("#products_search").serialize(), null, 'script')
    false
  )
Avatar

You really have stepped up your game by branching into these new technologies. I for one find this screencast invaluable. I have watched numerous screencasts, paid and free, and this was the easiest to grok. Keep up the great work and I'll keep paying you monthly :D

Looking forward to the Spine, KnockoutJS and Ember screencasts.

I would also like to know what you would personally invest time into learning for the future? It seems that it's a toss up between Backbone and Ember

Avatar

Awesome Stuff!

No worries on the length, please do follow up casts!

I've learned a ton!

Avatar

Glad to see more people talking about json templating for building apis. Here's an alternative to rabl that we wrote at Zaarly called bldr https://github.com/ajsharp/bldr

Avatar

Yes, take a look at using the node keyword because this allows for very flexible responses. Just added the beginning of a guide for it here: https://github.com/nesquena/rabl/wiki/Flexible-Responses

Avatar

also check out joey b's backbone screencasts.

his are paid screencasts as well. both ryan and joey's are excellent. happy to support both guys.

Avatar

Thanks heaps another marvelous cast

While following along I had trouble formatting the coffee script correctly in textmate any ideas?

Cheers
Dave

Avatar

What's about batman.js? :-)
Made by the shopify guys and looks very interesting!!
Unfortunately, there are not very much good tuts/videos out there.

A whole series about JavascriptMVCs would be absolutely awesome!

Avatar

I've been working a lot with Spine lately, and it's very nice. There's a spine-rails gem that makes integration really easy.

Avatar

I do hope to cover other JavaScript libraries such as Knockout, Spine, and Ember in the future. Not certain when or in what order. Thanks for the suggestion.

Avatar

I'm calling Entry.update (class method) so it has no context of the entry record I'm trying to update, which is why it is necessary to pass params[:id] to it. The params[:entry] contains the attributes that will be updated.

Avatar

I hope to cover Twitter Bootstrap in the future, thanks for the suggestion.

Avatar

Good point, I'll look into this and consider covering it in part 2.

Avatar

Fixed the link and I'll look into the cut-off issue. Thanks for letting me know about these.

Avatar

Thanks for mentioning this. I was debating between backbone-on-rails and backbone-rails, both are great projects. Went with backbone-on-rails because of the simpler generator was easier to build off of.