RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Just a quick follow up, minitest-rails-capybara is working now.

Avatar

XML spreadsheets MUST have the .xlsx extension

Avatar

This is the to_xls gem that I'm using. It's perfect for spitting out simple arrays with limited formatting but unable to tackle anything more involved.

https://github.com/splendeo/to_xls

An example of my use:

http://stackoverflow.com/questions/11112581/calling-an-activerecord-association-method-from-an-array-in-rails-3-2

Avatar

Excel will also always throw a "unreadable content" error when opening a SpreadsheetML file. It's just a crappy user experience all the way around; do not want.

Avatar

Same issue here. What's more, removing the register statement from mime_types.rb may break your app in production.

Avatar

If you need it simple then acts_as_votable will be a solution for you. activerecord-reputation-system has some advanced options.

Avatar

Aha, I see, thanks for sharing. May be acts_as_votable replaces the doing from scratch approach.

Avatar

thanks for good tips in advance.
I have a question.
what is DSL?

Avatar

So the image that gets retreived from Twitter is the lowest resolution one. I am calling it in the user.rb like so:

def update_picture(omniauth)
self.picture = omniauth['info']['image']
end

How can I get one of the better quality image from Twitter?

Avatar

One thing that bothers here is the need to change the URL parameters to be part of the path; Google (Webmaster Tools/URL Parameters) won't pick them up when they are.

Is there anyway round this so that we can keep them a parameters?

Ryan, I notice that you still have them as parameters. Does that mean you're not caching the Episodes index pages?

Avatar

I've fixed the issue in the ASCIIcast by removing the '↵' which didn't really seem needed anyway.

Avatar

I am using Rails 3.2 and I am getting the following error from Paypal's sandbox site:

We were unable to decrypt the certificate id.

I have tried re-generating certificates just in case. I have played around with the data in my shopping cart etc. I am not really sure how to debug this issue :(

Any help or insight would be greatly appreciated!

Avatar

Great episode as always.
I found we can apply this from-scratch solution to implement facebook-like 'Like' button. Or is there any gem to do this already?

Avatar

As usual, a really useful and clear episode, thank you Ryan.

Just a couple of minor points. In the ASCIIcast, there is unrendered '↵' (in the config/environments/development.rb section).

Also, for people who have never used the mailer before (like me), it might be worth pointing out there is further configuration to get the Mailer fully working, as outlined in your Action Mailer railscast.

Avatar

Maybe it's about something not covered in this episode, which is indirect reputation computing? Look at examples: https://github.com/twitter/activerecord-reputation-system/#usage-example

Avatar

Thanks for the episode!

Is there a best practice for leaving room for new "haikus" to still have a shot at appearing at the top?

Would it be a good idea to prepend @haikus in the index action with a few of the more recently created haikus?

Avatar

Rails is not a PHP framework where every request always destroys and creates all variables and object over and over again. In Rails class variables are created once during boot time. They are not recreated with incoming new HTTP request. So in multithreaded mode those variables should not be changed or should be guarded by mutex.

Avatar

Thanks for the great examples. I have a question. One table I wish to show has 3 links to associated tables, and I want to use those associated fields as args for sorting and searching. I cannot work out the syntax in the Ruby class; if it's possible.

When I look at the log I can see 4 queries for every row, the first for the main table and another 3 for each link. Seems very inefficient.

I have this code in the model:

class Neighbour < ActiveRecord::Base

belongs_to :locality, :class_name => "Locality"
belongs_to :neighbour, :class_name => "Locality"
belongs_to :highway, :class_name => "Highway"

default_scope joins(:locality, highway).order('localities.name')

end

In straight SQL I would achieve this with one query and let the database optimise the method. How would I do this to supply a view of data to the dataTable?

Thanks

Avatar

I have one question about the class variable that is preceded by @@, I know that the Web is stateless and everytime a request comes to a server it is as if it's the first time they meet each other. since I don't see any database in the example, the @@counter must be incremented 5 times to get to the number 5, but if it loses its state in each request, how does it ever get up to 5? does that repeat 5 command tell the connection to stay alive for another request? or is that & at the end of the curl command doing this? I hope I am making sense here...

Avatar

I am having issues setting up my mail server (Mac Mini using Lion Server). I get different answers on how to set this up when I call technical support. When I try to send emails it sits until it times out. It is looking for something on my server but I do not know what information to put where. This brings me to my question.

For ease I wanted to use my Gmail smtp settings for my Rails applications. However it appears that Gmail will force the FROM value to the Gmail email address and name (if one is set up) regardless of what the FROM value in the mailer is. Is there any way around this using Gmail? If not are there other email services that are as easy to configure as Gmail is but do not force the FROM value to be the email address? This was not addressed in this railscast.

Avatar

Devise is really great as are all Ryan's episodes. But I don't believe that everyone uses only this type of authentication/user management (database stored). What about LDAP for enterprise deployments? Any good gem for LDAP backed user/group database?

Avatar

How would you test if the exception was successfully raised and errors logged using RSpec?

Thanks in advance!

Avatar

If you do it the way episode #237 does it you will be good.

Avatar

It looks like Ruby 1.9.3 has a different idea of Date.parse. It doesn't want to parse the date from the query string as it was in the Cast.

def index
  @events = Event.all
  @date = params[:month] ? Date.parse("01-#{params[:month]}") : Date.today
end

Had to add the first day of the month to the controller to get it to parse it correctly. Else it parses it as if the month is the day, so the calendar never appears to change.

Avatar

Hi Andrew,

Once we have the production working as we have in this video, is this just good enough to configure staging or any other environment of the same app? what about to run one more app in the same server.

Thank you

Avatar

I don't know what makes this gem different from the existing acts_as_votable gem https://github.com/ryanto/acts_as_votable?

Avatar

You can define them in the environment rb files. So, for dev, you can define them in the development.rb file. You can have a separate Twitter app, then, for production and put those keys in the production.rb file.

Avatar

Can anyone tell me how to do the client side validation in dynamic text fields. How to validate for presence_of for the dynamic text field so that at least one dynamic text field must be present in the form.

Avatar

Very useful screencast and I was interested in this when T-Love originally posted.

Anyone know if attr_accessible is considered a class variable (i.e., requiring a mutex lock if I enable Threadsafe!)?

Example --

I have a Post model that dynamically sets attr_accessible from the Posts controller based on a user's permission.

The controller action first looks up the user and then looks up the user's permissions (for example, an admin user would have all fields accessible.) Would I wrap this in a mutex? Any idea how to even test concurrent action calls with more involved than just hitting a controller action with a generic get (i.e., a put or post with data...)?

Avatar

Thanks for the video, I found it very useful. You mentioned at the end that Rails' controllers are limited by database Pool connection size, even when you're not using a database connection in your action. That kind of floored me, I've written tons of controller actions that never talk to ActiveRecord, never realizing that AR could still be a bottleneck.

Avatar

I had the same problem, in my case I had to reinstall the pg gem and everything worked fine. This post was useful:

http://tammersaleh.com/posts/installing-postgresql-for-rails-3-1-on-lion

Avatar

+1

btw. could someone tell how would look like updating same records by different threads? Checking updated_at or some locks?

Avatar

I don't think that it will help you, because of preload_frameworks. Normally classes are lazy loaded - so you have only classes that you need in memory. With this option everything will be loaded at start. If you want to remove Rack::Lock I would rather check if there's an separate option for it.

Avatar

You mentioned Rubinius/JRuby - how about an episode deploying to these platforms?

Avatar

It is possible to get around the encoding issues for csv-formatted excel files: use UTF-16 little endian encoding (with a byte order mark).

ruby
BOM = "\377\376"
BOM + Iconv.conv('utf-16le', 'utf8', data)
Avatar

what would be the best strategy to combine it with e.g. omniauth-facebook?

Avatar

I'm using Unicorn in production, and I have a (probably) dumb question. If I enable threadsafe, will this help (even if just slightly) the memory usage by not loading the Rack::Lock middleware?

Avatar

I'm tending to agree after my initial relooks at Devise. I liked how Sorcery is very non invasive. However, it doesn't seem to be as fully functional out of the box. There's a bit more configuration work to be done with it (not always a bad thing).

Avatar

Sorry. Didn't fully understand your question. Answered prior to watching episode. ><

Avatar

I'm wondering if the encrypted password that Devise uses is more secure or equally as secure as the salted password that Sorcery users. The last thing that I would want to happen is to be a repeat of what LinkedIn recently faced. Any thoughts?

Avatar

I've actually been having troubles storing the tweets in the database. With using postgresql, I get this error:

: SELECT 1 AS one FROM "tweets" WHERE "tweets"."tweet_id" = 222042501954019328 LIMIT 1
ActiveRecord::StatementInvalid: PGError: ERROR: operator does not exist: character varying = bigint

I had to actually declare the table creation differently.

ruby
class CreateTweets < ActiveRecord::Migration
  def change
    create_table :tweets, :id => false do |t|
      t.integer :tweet_id, :limit => 8
      t.string :twitter_name
      t.text :content

      t.timestamps
    end
  end
end

per this article: http://moeffju.net/blog/using-bigint-columns-in-rails-migrations

Not sure if this is the best method - but currently working on my end!

Avatar

I overcame a problem with the above, which occurred when I submitted the email to which the password_reset email should be sent. It would say:
ActiveRecord::RecordInvalid in PasswordResetsController#create
Validation failed: Password is too short (minimum is 6 characters), Password confirmation can't be blank
I have no idea why it would say that, but the above fixed it. What exactly does
save!(:validate => false) do?

Avatar

How would we do to do it remotely ?

like :remote => true

Avatar

I haven't used it, but this looks like a viable option for more complex needs where you really want to use a template approach:
https://github.com/dasil003/csv_builder