RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

i needed to use 2 different classes to get this to work in my project. this was a good explanation but wouldn't work for me since I was already using carrierwave on a live site and had images uploaded to specific folders already on S3. What I did was created an uploader class ImageUploader using the CarrierWave_Direct gem like in this example, and then kept my original class but renamed it to ImageProcessor. This way the original uploaded file is saved in a different folder in S3 and then I don't have to change the folder structure for current photos on my site. you can check out my solution here if interested:

http://stackoverflow.com/questions/14791655/carrierwave-direct-gem-keep-current-directory-structure-on-s3/14842832#14842832

Avatar

I've had some luck placing angular "apps" into separate partials that can be accessed as templates by AngularJS. If Rails renders server side, real data is used. If angular requests the "partial" via Ajax, I give it sample data that is removed when Angular binds to the template.

Avatar

Thank you Luke for mentioning that!

Avatar

Yeah, that is a really great explanation. Thanks.

Avatar

I've successfully built it for Lion with Xcode. I just needed to replace the Deployment Target from 10.8 to 10.7

Here is the link:
https://dl.dropbox.com/u/9189157/SublHandler.zip

Avatar

Thanks for the simple contribution! I've never messed with coffescript before and I'd have had no idea that spaces instead of tabs would mess my code up so much!

Avatar

I have solved this same problem using a column where I store the original locale, and overriding a method set in Globalize3::ActiveRecord::InstanceMethods. Here is the code:

def globalize_fallbacks(locale)
  if record_fallback?(locale)
    [locale, original_locale]
  else
    Globalize.fallbacks(locale)
  end
end

def record_fallback?(locale)
  respond_to?("original_locale") and
    original_locale.present? and
    original_locale != locale
end

It works fine. I don't know if there is any downside...

Avatar

Here's another nice gem that can handle exporting data to CSV, Excel, JSON, and HTML:

Dossier

https://github.com/adamhunter/dossier

Avatar

thanks a lot! (works with FireFox and Chrome)

Avatar

@Nic - I know your question is very old, but if you want to integrate Rails with Open Directory Apple has some example code. Unfortunately you need to own OS X Server to view it. Apple uses Ruby on Rails to implement their wiki server and profile manager applications. Dig in to the Server.app bundler and look for a folder called webauthd. The ruby code for md5 authentication with Open Directory is in that folder.

Avatar

Sorry, better use this:

password_reset.text.erb
<%= edit_password_reset_path(@user.password_reset_token, :locale => "#{I18n.locale}") %>
Avatar

what is the best way to load seed data for a new tenant?

how about adding load Rails.root.join("db/seed_tenant#{id}.rb") to create_schema:


def create_schema
connection.execute("create schema tenant#{id}")
scope_schema do
load Rails.root.join("db/schema.rb")
load Rails.root.join("db/seed_tenant#{id}.rb")
connection.execute("drop table #{self.class.table_name}")
end
end

Avatar

The filename is not getting set using your method. Is there a different way to set the filename?

Avatar

For anyone who is working with different locales (like Remmington above), make sure your mailer template looks something like this:

password_reset.text.erb
<%= edit_password_reset_path(@user, :locale => I18n.locale, :password_reset_token => @user.password_reset_token) %>

Especially when you have routes like these:

routes.rb
scope '(:locale)' do
  resources :password_resets
end

It took me ages to figure that out...

Avatar

I just tested this app and can confirm your assumption. It kept on recreating the thumbnails.

Avatar

It's true that understanding the inner workings of frameworks is very valuable. I was quite excited when I saw this railscast for that very reason. The problem is that zipping through a large number of classes & modules scattered about a number of unfamiliar files at high speed is simply not useful in learning Rails internals.

Avatar

I just merged the nested_urls branch to master and released a 0.1.0 version of the gem with that functionality included.

Avatar

Make this change in routes. And it works.

resources :styles do
collection do
match 'search' => 'styles#index', :via => [:get, :post], :as => :search
end
end

Avatar

Great Cast!

FYI, Bootstrap components written in pure AngularJS:
http://angular-ui.github.com/bootstrap/

Avatar

Another Awesome screencast! Very nice Mr. Bates.

Avatar

Hi

I am trying to use will_paginate with ransack.

controller
@search = Style.search(params[:q])
@styles = @search.result(:distinct => true).paginate(:page => params[:page], :per_page => 5)

index
<%= will_paginate @styles %>

Rest of the code is same as in this tutorial. But pagination links are not working. Really stuck with it. Please help.

Avatar

Thanks for the post Ryan, you don't have any idea how much you helped me so far. :)

By the way, rails g spree:site is not the generator right now. It is rails g spree:install anymore.

Avatar

Thanks Jaroslaw for the quick but important tip about Node.Js I want to look at Joosy too.

Avatar

Thank you Travis for this information. TodoMVC will help me, i assume, in the near feature.

Avatar

It is not working for me. I used both FireFox and Chrome, and I click on "Launch App", but nothing happens

Avatar

You are so right, I have tried AngularJS in the past and it's obstrusive if you want the two way data binding with Backbone use rivets.js, you can check an example I have done http://boriscy.github.com/backbone-rivetsjs/

Avatar

The different parameters and the jQuery don't seem to work together for me. Do you guys have any idea why this happens?

http://stackoverflow.com/questions/14569721/rails-parameters-get-lost-because-of-jquery-link

By the way: since jQuery 1.9 it is ".on("click", function()" instead of ".live("click", function()".

Avatar

Thanks Michael. Exactly what I was looking for.

Avatar

Hi can you help me
I'm trying to open rails console and getting this
deployer@microv:~$ rails console
-bash: rails: command not found

Avatar

thanks a lot of your help ,,It will be y pleasure to contact you

Avatar

See Sanjeev's and my replies below

Avatar

See Sanjeev's and my replies below

Avatar

Agree! I don't like cluttered views. I feel Backbone is a more elegant and unobtrusive solution.

Avatar

I'm having trouble moving the code that generates the pdf from the controller to a separate ruby file.

I have the following code in the relevant part of my controller:

def show
@corporation = Corporation.find(params[:id])

respond_to do |format|
  format.html # show.html.erb
  format.json { render json: @corporation }
  format.pdf do
    pdf = CertificatePdf.new
    send_data pdf.render, type: "application/pdf", disposition: "inline"

I created a separate certificate_pdf.rb file in the folder app/pdfs which contains the following code:

class CertificatePdf < Prawn::Document
    def intitialize
        super
        text "Help"
    end
end

However, when I open the generated pdf the document is blank. Any thougths?

Avatar

I'd like to second that. I spent an hour fiddling with Taps. I was done with my intended task five minutes after hearing this post about valkyrie. Just lovely. Thanks!

Avatar

Hi Ryan!
It will be great if you can make a screencast showing us how to deploy an app on 2 servers, one for the Rails app itself and the other one for the database( Postgres). This is probably the first step I might do when I want to scale an app, but still, I can't find materials about how to do it right.

Thank you!

Avatar

Im struggling to get this solution to start with the environment set as staging.

I have tried updating the unicorn init file to pass the -E argument:

CMD="cd <%= current_path %>; bundle exec unicorn -D -c <%= unicorn_config %> -E <%= stage %>"

But Rails.env always says production.

Any ideas?

Avatar

Anyone tried this setup with SSL? I'm getting pretty tripped up with this config.

I added:

ruby
    "ssl" => {"port" => 8443, 
      "SSLCertificateFile" => "/etc/nginx/server.crt",
      "SSLCertificateKeyFile" =>  "/etc/nginx/server.key"}

To the trinidad config block.

However trinidad continues to looks for the keystore file instead of using the certs.

Avatar

Thanks Sanjeev,,,for those who don't notice the subtle difference... Morris.Line({....}) needs to separate each different chart/graph call with different tags...otherwise it will only see the first and you'll get the "'Graph Placeholder not found'" or "Element not found" errors.

Avatar

Hi Daniel , had the same problem. In your controller if you have a respond block you have to add respond_to js. If you dont have a respond block it will look for js.erb automatically.

Avatar

+1 I was actually a bit surprised to see an angular screencast before an ember screencast.

Avatar

Any comments on Meteor? is it still far from a JS framework for production?

Avatar

I got the same "can't convert Array into Hash" error from

products_controller.rb
format.csv { send_data Product.to_csv(@products) }

but it seems to work if you pass @products as a variable into the model by adding it in the parentheses and in the .each loop as I'm passing all_products in below.

product.rb
def self.to_csv(all_products)
  CSV.generate do |csv|
    csv << column_names
    all_products.each do |product|
      csv << user.attributes.values_at(*column_names)
    end
  end
end

The advantage is that you can define @products in the controller in order to only get the products you want such as in this example:

products_controller.rb
@products = Product.find_all_by_color("green")
respond_to do |format|
  format.csv { send_data User.to_csv(@products) }
end      
Avatar

Now Ryan, if you can just change this from products to personnel records and add workflows, the app I need to write will be done.

Thanks again, Ryan.