RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

While there are some things like graphs that do not interop very well, I have never experienced Numbers opening up an xlsx file as raw XML. Interested to hear what version of Numbers you are working with. I Currently using 1.2 (436) for confirming https://github.com/randym/axlsx interoperability with LibraOffice and Numbers

Avatar

Keep in mind that Excel XML output is not readable by Apple Numbers.

Numbers will display the raw XML. It will take the older 'native' Excel format.

Come on, Apple, I want to like the program but the last update was 2009...

Avatar

Will it doesn't say (AFAICS) in the stripe documentation that Stripe will not work in production without it, the docs do recommend having it. (My guess is that it will not work in prod mode without SSL)

https://stripe.com/help/ssl

In pro episode 357 Adding SSL, Ryan suggests going as far as making all sites that collect user information or require login of some sort to use SSL.

Avatar

Yes ++
I need it all the time when a customer has a huge amount of legacy date in XLS format they want to move online

Avatar

No, it's calling those methods on the request object (the one that has request.path, request.remote_ip, etc).

Avatar

You override the https requirement for all the actions in a controller with:

private
def use_https?
false
end

How would you do it on an single action or a subset of all the actions in a controller?

Thanks

Avatar

Hi Ryan

I am trying to set up Private_Pub but I have a conflict with Rack.

I see this message:

You have already activated rack 1.4.1, but your Gemfile requires rack 1.3.6. Using bundle exec may solve this. (Gem::LoadError)
from /Users/bedomax/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:17:in
setup'
from /Users/bedomax/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler.rb:110:in setup'...........

My rails is Rails 3.1.3 and Ruby ruby 1.9.2.

Thanks for your help.

Regards
Maximiliano

Avatar

Hey Ryan, thx for this.
I have a problem though with Mongoid
A Person model and Custom Attributes model. Person embeds_many custom_attributes. Everytime the update_attributes(params[:person] creates a brand new set of attributes with a new idea instead of updating the existing ones.
Any idea why and how to fix this ?
Thx

Avatar
def self.generate_csv(fields, records, options = {})
  CSV.generate(options) do |csv|
    csv << fields.collect(&:humanize)
    records.each do |record|
      csv << record.attributes.values_at(*fields)
    end
  end
end

generate_csv([:id, :username], members, options[:csv])

Avatar

it does not automatically update, how to we fix this?

Avatar

Kevin, do you have anything you could point me to as far as blog posts or documentation on how you went about setting up torquebox on EC2? I've fallen in love with torquebox in the last couple days and I want my ultimate destination to be EC2. It would be nice to use Rubber to help manage this. I see you've created a torquebox template, I'm just wondering if you have any documentation on how you've used it and how well it has worked for you. Thanks!

Avatar

Hi guys,

wondering if anyone has tried this by submitting the form by AJAX?

I've got the first step that creates a new Project, then we redirect to the project_steps_path to go to the actual first step of the wizard. This works fine until we submit the form via AJAX where we just keep getting a 302 response Moved Temporarily, the Project does get created and I think the redirect to project_steps works, but instantly redirects again to the Project/index view.

I'm hoping to be able to submit by AJAX and in the response get the next views HTML

Has anyone else experienced this or something similar?

cheers
Chris

Avatar

Things I found useful while working on this:

Avatar

I got the same, but after reinstall the pg gem, everything works fine.

Avatar

Thanks, same problem here, and same solution.

Avatar

Partially solved. Have included a specific route. No data in my table - will look further into that.

Thanks

Avatar

Getting error in view:Extract from log:
Highway Count at list: 229
Rendered highways/list.html.erb within layouts/application (107.9ms)
Completed 500 Internal Server Error in 164ms

ActionView::Template::Error (undefined method `highways_url' for #<#Class:0x98d7c4c:0x98d66a8>):
5:

6: <%= link_to("Add New Highway", {:action => 'new'}, :class => 'action new') %>
7:

8: ">

highways.js.coffee:
jQuery ->
$('#highways').dataTable
sPaginationType: "full_numbers"
bJQueryUI: true
bProcessing: true
bServerSide: true
sAjaxSource: $('#highways').data('source')

Rails:3.2.1.
What other information can I supply?

Thanks

Avatar

apply the pagination until the format.html inside respond_to
format.html { over here }

this way format.csv is not affected by paging

Avatar

I am using will_paginate in a search page. After restricting the number of records according to the search form fields I am calling paginate on them.

When I export to CSV I only export the current number of records on the page as defined in :per_page. How do I trick my controller to export all records when export to CSV?

Avatar

<%= link_to "Excel", user_contacts_path(format: 'xls'), :letter => 'c' %>

should do it...

Avatar

You can use
<%= link_to "Excel", user_contacts_path(params.merge(format: 'xls')) %>

and this will maintain the current parameters you have plus the ones you add or edit inside merge.

Avatar

Importing CSV files would be a great pro epsidoe also.

Avatar

in an index view that already does sorting and filtering, stuck on one point: creating a link_to that passes those parameters back to index.

so from http://0.0.0.0:3000/users/198/contacts?letter=C

this link_to
<%= link_to "Excel", user_contacts_path(format: 'xls') %>

passes
{"action"=>"index", "controller"=>"contacts", "user_id"=>"198"}

How do I preserve my variable number of parameters?

Avatar

I see, but how do I intercept /auth/twitter ? it's not a common action and before_filters don't work.

Avatar

i did the same as explained in the cast (only server-side), but when i click on the link i always get only a code back like this:

{"code"=>"AQAlwnb3kkcjBB0qkPJbPFeTlroBOVO5_daVPuqUEeghQtQqK8cjlGf5qqaQOHXiFpQXsHY07jwHsVEo07i35YBhN33kruM94KV2NpZSWj_Vsw4CrfTUSUD6-GT4y_THeojXtLUJXWyM9TF3XnnFrBA_ECCn5nhoNynxB6KyUm8M8Uw23C2YeeJJuJd9-dUrLkg",
"provider"=>"facebook"}

and therefore the

TypeError in SessionsController#create
can't convert nil into an exact number

does anyone know what i am doing wrong?
thank you!
Daniel

app/models/user.rb:8:in at'
app/models/user.rb:8:in
block in from_omniauth'
app/models/user.rb:3:in tap'
app/models/user.rb:3:in
from_omniauth'
app/controllers/sessions_controller.rb:3:in `create'

Avatar

This is the only one I know about - not quite as smooth of an API but if you are dealing with a fixed template it is great.
https://www.ruby-toolbox.com/projects/odf-report

Avatar

Honestly, Ember.js is changing really fast at the moment. I would probably wait till certain approaches settle down.

That said maybe Mustache, or HandlebarJS could get their own episode.

Avatar

How about an episode on Importing csv/xls files to your app?

Avatar

This is great! Does anyone know about similar gems for Open Document?

Avatar

All of a sudden I'm facing the same error as well, and it's happening on more then one projects, so shouldn't be in the asset files...any ideas anyone?

Avatar

+1, we use axlsx for reporting and found it very helpful. Also Randy has been very responsive in case of questions!

Avatar

Hi Yarin,

I'm getting the exact same thing. All I get is a blank dialog with the Facebook permissions url (https://www.facebook.com/dialog/permissions.request?....). Does anyone know if there is there some magic to getting localhost to play nicely? It seemed to work for Ryan with no problems.

Avatar

+1 axlsx cast. It saved my time

Avatar

cache can take an array, so you should do cache [testimonies, Date.today], no?

Avatar

Thanks Yannick. It has been a true community effort. Huge respect to the people out there who forked and added the feature they needed. I'd love to see a Pro cast showing chart generation, multiple sheets, styled and localized headers and all that jazz. For now, here is a blog post showing how easy it is.

http://axlsx.blogspot.jp/2011/12/using-actsasxlsx-to-generate-excel-data.html

Avatar

+1 For Ember.js. I watched the Ember crew sharing their product here: http://vimeo.com/36992934

Avatar

Anyone trying translating ? I tried this, as mentioned in API docs:

http://api.rubyonrails.org/classes/ActiveModel/Translation.html

class TranslatedPerson
  extend ActiveModel::Translation
end

Actually what I am trying to do is translate the error messages. The message part like "can not be empty", etc. worked, but the attribute names still in english.

Avatar

Thanks Randy! You really helped us with that gem:)

Avatar

Well that's maybe a bit short for a "Pro", you just need a few lines to do that ;)

Avatar

Another useful idea for a "Pro" episode on this topic would be generating the document while using pagination for just a page of data, or after filtering results and exporting a document with just those results.

Awesome episode as always though, thanks!

Avatar

While it is primarily a tool for making PDFs, you can also use DocRaptor to generate XLS, if what you need is more involved. Being able to select pdf instead of xls without too much additional effort is a nice bonus, and it is also available as a heroku addon. Yes, there is a small document fee after the first five, so clearly not suitable for everything.

Avatar

The only issue that I saw with the CSV export was that it would return all data from that table. I put it on a user list and has to make a index.csv.erb file that would post just the required data.

Not a big deal since I was able to put in whatever information I wanted.

ruby
First Name,Last Name,Email Address,Status,Company,Last Login,Last IP

<% @users.each do |user| %>

<%= user.first_name %>,<%= user.last_name %>,<%= user.email %>,<%= "Active" if user.user_status %><%= "Inactive" if not user.user_status %>,<%= user.company.company_name %>,<%= time_ago_in_words(user.updated_at.localtime) %>,<%= user.ipaddress %>

<% end %>
Avatar

I can't remember the details but I was having trouble with localtunnel so I wrote this little one liner that has been working perfectly for me for a while.

I have test callbacks from a few services configured use this url for development debugging.

#!/usr/bin/env bash
ssh -gtNR 3000:localhost:3000 you@yourserver.com

In case anyone else can use this.