RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

First of all - thanks for the awesome Railscast.

I had same issues as described above. Solution:

_ read the README in the git repository https://github.com/jejacks0n/mercury/ exactly
_ use gem 'mercury-rails' in your Gemfile without pointing to the git repository
_ fire bundle update
_ make a backup of your changes in mercury.js
_ make a backup of your changes in mercury.html.erb
_ fire rails generate mercury:install
_ use the changed eventhandler declaration described from Chris Sessions above
_ use saveStyle: 'form' in mercury.htm.erb
_ throw away your backups - you don't need them ;-)

You should not have problems anymore. Relax!

Cheers

Andy

Avatar

Does someone of you use this gem and has custom validations in a model?

I have something like this, but ActiveAdmin ignores it.

ruby
validate :validate_me

def validate_me
  self.errors[:base] << "My error message" if my_validation(self.id) == true
end
Avatar

Thanks Shamim! I was just searching around for some way to keep my views in HAML.

Avatar

I have the same problem as jayeshmori. Did you find a solution?

Avatar

Hello, nice screencast, Thanks!!

Do you know where can I find a nested resources example with backbone?

I want to "nest" entries to users like this: users/:user_id/entries and show them into that nested url (not into users/:user_id).

Avatar

I'm also curious about this. I would like to move template-related things from my ApplicationHelper into ApplicationDecorator (such as site-wide logo, sign in/out links, etc). I tried simply moving the code over, but then ran into problems trying to test and reference ApplicationDecorator.

If ApplicationDecorator is just meant to act as a global parent that all children will have access to, that's fair, but then to repeat darwalenator's question - what would be the appropriate place for such code?

Avatar

Can any one look at the following question related to mountable engines? I urgently need it to solve,

http://stackoverflow.com/questions/9310287/rails-3-1-engines-gemspec-and-config-initializers

Avatar

products_url comes from the routes, and j is a method to escape the output so that it can be used with javascript

Avatar

I am trying to use friendly_id with ActiveAdmin and I am sending friendly_id in my model a function showdate_as_url

ruby
  def showdate_as_url
    "#{showtime.strftime("%Y/%m/%d")}"
  end

to get this to work I have this in my routes:

ruby
  resources :episodes, :id => /[0-9]+\/[0-9]+\/.+/

All works great outside of active admin, but in the active admin scope this date based url dose not work. I have tried setting the to_param back to id with a before filter in active admin - which works again, but then leaving active admin my friendly_id does not work any more.

Any ideas anyone?

Avatar

One interesting difference between rake and thor: If you have a compile error in just one of your rakefiles, "rake -T" doesn't work at all. But if you have a similar bug in a thor file, "thor list" will still display valid tasks from other files.

Avatar

"<%=j products_url %>";

products_url wasn't set as a variable anywhere. How did the above code get the url? localhost:3000/products

Why was the "j" necessary?

Avatar

Hi,

I implement the same solution but the mustache handler doesn't appear in the handlers list .

config/initializers/mustache_template_handler.rb

ruby
module MustacheTemplateHandler
  def self.call(template)
    if template.locals.include? :mustache
      "Mustache.render(#{template.source.inspect}, mustache).html_safe"
    else
      "#{template.source.inspect}.html_safe"
    end
  end
end
ActionView::Template.register_template_handler :mustache, MustacheTemplateHandler
error
Missing partial admin/services/users, admin/users, application/users with {:handlers=>[:erb, :builder, :coffee, :haml], :formats=>[:html], :locale=>[:en, :en]}. Searched in:
  * "/Users/damien/projects/moneywise/app/views"
  * "/Users/damien/.rvm/gems/ruby-1.9.2-p290/gems/kaminari-0.13.0/app/views"
  * "/Users/damien/.rvm/gems/ruby-1.9.2-p290/gems/devise-2.0.1/app/views"

Does anybody had this error before ?

Avatar

Thank you for the useful episodes Ryan.

I found it cleaner to use haml_coffee_assets as the template engine as you don't need to write your Html code using javascript. and you can simply use coffeescript inside your haml templates :)

Avatar

+10 on what you just said.

Probably start changing how we see and think about web servers with js gaining this kinda speed.

Avatar

The code up here is not any good but as frustrating as this gets. I try to host on heroku as it works most of the time.

Running 2 web: processes for the same app is not allowed on heroku. Maybe I understood that wrong. I'll try another type of process but it would help if anyone knows some answers to post them here. Just incase.

Avatar

Made my head hurt... but really great functionality.

It would be interesting to see this in conjunction with the offline app. It seems a whole client side application could persist and pull application updates from the main server when they are available. Potentially sync data, but really have everything live on the client indefinitely... making the web server a software distribution technology and data store rather than an application server technology. This would work wonders for scale.

Avatar

I'm thinking about using this technique to create a pop up for login. But not too sure how to procede (haven't tried yet, just thinking). I do know I need to send json from session#new function and use js to consume that and add it to the hidden lightbox. That's how I'm thinking about it, can anyone let me know if this sounds right...I'd like to use gon and possibly rabl too. Help appreciated.

Avatar

Any way to use this in a simple form/textarea?

Would like the wysiwyg and GUI without the additional backend requirements.

Avatar

That functionality is not available. The code:
view_helpers.rb

By the way, in case you want to subscribe to multiple channels you could do something like:

ruby
<% %w(/channel1 /channel2 /channel3).each do |channel| %>
  <%= subscribe_to channel %>
<% end %>

It's just an idea...

Avatar

I really want see next episode about backbone. When I started using backbone with rails I have big problems with rails associations and with more then one backbone router

Avatar

How do you deploy this on heroku cedar?

ruby
 # Procfile
 web: rackup private_pub.ru -s thin

thats what am thinking but am not sure about it. What do you think?

Avatar

@rosobas pointed this out but as people are still having issues, this is what the initializer should look work with rails 3.1 >

ruby
class ActiveRecord::Base
  attr_accessible
  attr_accessor :accessible
  
  private
  
  def mass_assignment_authorizer(role = :default)
    if accessible == :all
      self.class.protected_attributes
    else
      super + (accessible || [])
    end
  end
end

mass_assignment_authorizer now takes a role parameter...

Avatar

This is a massive complement to Ryan, but his tutorials really are the simplest to describe the functionality that he is trying to implement in the most elegant way. If you need more dumbed down perhaps you should a: not implement the feature, or do it in a less elegant way with before_save functions on particular attributes (which would work in most cases).

Avatar

Hey,

im using rails 3.2.1 and im new to this,
im unable to find the migration files which you specified in this tutorial,

all my requests for
users/signin are getting routed to index page, i dunno wat might the problem be.

can you help me with that?

Avatar

I agree with the previous comments.
It would be very nice to see this series continue with new episodes!

Keep up the good work!

Avatar

Can I ask a couple of questions here Ryan or others.

1) does the "sign in with google" use OAuth-2 or OpenID? Getting confused here. Reading the google pages it almost seems you need to use OpenID for "sign in using google", and OAuth to get data via google api's?

2) if I want to both (a) use "sign in with google" for authentication, and also (b) access data from a google api, then do I need to use two separate processes in rails for this? E.g. do I need to use say (a) OmniAuth to do the "sign in with google", and then (b) OAuth Plugin configured to google calendar API to get the data?

I ask this last question noting I've successfully so far used (a) OmniAuth to do the "sign in with google", and (b) OAuth Plugin to get google calendar API data.

Avatar

Solved.

Basically, you need to re-run save on the parent object after update_attributes has had a chance to do it's thing, such that the object stores the newly-generated filename — assuming you're using digest-esque filenames.

So I turned off the after_update directive and run the cropper manually in the controller, so I can save it easily:

ruby
def crop
    avatar = current_profile.avatar
    avatar.crop_x = params[:photo]["crop_x"]
    avatar.crop_y = params[:photo]["crop_y"]
    avatar.crop_h = params[:photo]["crop_h"]
    avatar.crop_w = params[:photo]["crop_w"]
    
    # Must re-save after update to ensure model refers to new version on S3
    avatar.crop_avatar
    avatar.save!
end
Avatar

I'm wondering this as well. I need to publish content that several different users (on their own channels) need to see.

I suppose I could do this by looping over the users and calling "subscribe_to" during each iteration, but I don't want the JavaScript to execute over and over locally.

Avatar

Ned — My models are set up in a nested fashion also, (Profile has_one Avatar) since I'm using a polymorphic "Photo" object in a couple different ways around the site.

Anyway, I'm running into an interesting issue where I'm successfully re-generating the new versions, but my Profile isn't picking up the updated Thumbnail — it's definitely saved on S3, so the actual cropping process is working very well.

Hrmmm, am I saving it incorrectly? Anyone run into something similar or have an idea?

Avatar

Turns out it had something to do with the mail client I was using to send the email from. (Microsoft Outlook for Mac)

Avatar

Ryan,
it is possible to subscribe to many channels, somthing like this:

subscribe_to "{'/channel_1', '/channel_2'}"

Avatar

I found this to be the case on my Linode running with lucid. Thanks for the tip.

Avatar

Thanks so much Ryan.

I has been beating my head against the wall trying to deploy on a clean unix box for days. This was straight forward and super easy to follow. I also love using vagrant to test my setup!

Keep em coming, best $9 a month I can imagine sending.

Avatar

I'm following along with this and I am having an odd issue that I cant figure out when saving the ticket to the database. Instead of it writing the To or From field as just the email address, its writing it in the form of "--- !seq:Mail::AddressContainer - email@address"

Anyone else ran into this?

Avatar

Is there any way to get the value of dynamically added text fields( not just the value of one text field) before saving it in my database? I have searched it in google but found no clue. Can any one help me? Thanks in advance.

Avatar

As pointed out by Luca Guidi lighthouse ticket, it's a matter of ordering.

You should call

ruby
<% content_for :my_section do %>
  <%# ... %> 
<% end %>

before

ruby
<%= yield :my_section %>
Avatar

This has been my experience as well. I've tried to move away from Rails in favor of a lighter weight solution on a number of occasions. Each time I've ended up migrating back to Rails at some point because of some feature(s) it gave me out of the box, or for some feature(s) provided by a plugin/ gem designed to work with Rails. The two biggies in the last project I did this with were the asset pipeline, which works really nicely with Backbone (especially with the eco template gem), and Devise for authentication.

Avatar

@jc Looks like the Regex approach only works for non-memcached solutions. For those using memcache, it sounds like a versioning approach would work best: http://stackoverflow.com/questions/9283141/expiring-cache-key-path-trees-for-resources

Avatar

I am curious why one may want to use this type of caching over HTTP Caching (with Rack::Cache, for example)...

Avatar

+1 for testing (Jasmine, Evergreen perhaps?)

Avatar

You definitely could. Still, in my experience, whenever I try to go light-weight, I realize how much Rails does for you, without you even knowing it. Like ActiveRecord integration with all kinds of handy tasks, CSRF protection, the asset pipeline, a rich set of gems/plugins, hundreds of helpers in controllers and views, and so on. What I'm trying to say is: Sinatra and Node.js are awesome tools, but be sure to know what you're getting yourself into. :)

Avatar

Does anyone have any tips for testing generators?? It looks to me like test/unit has some helper methods for testing generators, but I haven't been able to find any references or tutorials.

Avatar

Finally got this working with rails 3.1! It took some puzzle skills. The last part I was having an issue with was that the search wasn't noticing the first letter. It turned out to be a case sensitivity issue, and using ilike rather than like, solved the problem.

Thanks for posting your solution pulp! I was beating my head against the wall! I'm using PostgreSQL locally - in case that helps anyone else.

Avatar

+1 for Backbone/Rails/Twitter bootstrap - very cool

re: Coffeescript/Backbone/Datatables - you might want to check out Slickback - a plugin that integrates Backbone and Slickgrid.

Avatar

Thanks for that link on testing! pretty useful...

And I'd like to hear Ryan's POV on moving away from Rails if you're leveraging MVC on the client. I agree that rails seems a bit overkill for single page/web2.0 app (like Trello).

To push your point further - it almost felt like extra work to use server validations in this episode.

Avatar

This was great! I (think I) know backbone and this episode had tons of useful extras that either taught me something new, or really solidified a concept - priceless!:

  • example where the context changes...
  • handling server errors/callbacks in a view
  • using wait judiciously
  • custom events
  • refactoring in backbone
  • catchall push state

Here's suggestions for Part 3:

  • testing backbone apps
  • tdd'ing backbone apps
Avatar

I had a problem. When I changed the "country" dropdown sometimes it selected the wrong values for the "province" dropdown. Solved it like this:

ruby
country = $('#cat_category_id :selected').text()
province = $(countrydropdown).filter("optgroup[label='#{country}']").html()