RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

I tried using this with an app that has Active Admin. Doesn't want to play nice. Gives the error "undefined method `downcase' for nil:NilClass". When I take out Active Admin, it works fine. Anyone else run into this?

Avatar

I correct this issue changing the permission of public/assets folder to this --> chmod o+rx, now works fine.

Avatar

I have a problem, my nginx server is running with nginx user, and when the application try to access the /assets files i have a 403 http error. I changed the nginx user to deployer group but the issue persists. Can you help me to fix this? The only difference between your post and my server is i'm running in a centos distribution.

Avatar

Where does it store the data? Does it override internationalization files?

Avatar

Hum, just wondering, I don't know nginx much, but as the unicorn socket has the app name in it, shouldn't the upstream be something like unicorn_<%= application %> so that there can be more than one ?

Avatar

It is being actively maintained by two former clients of Thoughtbot that heavily use Copycopter going forward.

Avatar

There are some plans to make it a mountable engine.

Avatar

gem 'thin' should be in Gemfile for this to work:
rackup private_pub.ru -s thin

Avatar

This is my question too!
Does it make sense to invest time to learn another tool, when capistrano seems to be able to make any task on any number of servers?

Avatar

Wow, this is great. I usually use apache+passenger and a MySQL database. Tried to read up on the differences and benchmarks, but it's still not clear to me: is it just a matter of personal preference or is this setup (postgres, nginx, unicorn) really faster/better?

Avatar

Any plan to convert this into a mountable engine? I still found it a hassle that it has to make a call for each page request.

Avatar

Great episode but I wasted some valuable time on a silly issue. The omniauth-aouth gem is gobbling the app errors and its pretty difficult to debug them.
In this case,the following needs to be changed in the user model to

user.name = auth["info"]["name"]

instead of

user.name = auth["user_info"]["name"]
Avatar

Hey Ryan - it would truly be AWESOME if you could include your Linode server setup script and share it over there!

Avatar

Ryan mentioned in the screencast that it used to be a paid service, but since thoughtbot decided to shut it down, they have open sourced it for everyone to use, hence this episode.

So you can still use it, as shown by Ryan, you just have to host it yourself (for better or worse).

I would recommend reading the post over at the thoughtbot blog as well.

As a side note, if copycopter isn't enough for you, Locale is also worth checking out.

Avatar

Does this link mean anything? Says they are shutting it down.

Avatar

Great screencast as always.

However you should not check configuration, especially secrets, into code.

CopycopterClient.configure do |config|
  config.api_key = ENV['COPYCOPTER_KEY']
  config.host = ENV['COPYCOPTER_HOST']
end

$ heroku config:add COPYCOPTER_KEY=8df4bc164dd COPYCOPTER_HOST=strong-dawn-1901.herokuapp.com
Avatar

Sometimes Chef just seems so heavy. Using Capistrano for provisioning would means one less tool to learn...

What problems does Chef solve that can't be addressed by Ryan's Capistrano approach? I know chef is good for large deployments, but for small/medium sized systems this Capistrano approach seems great.

Avatar

Looks like the client has decent caching, and co-processes that keep it up-to-date. Cool!

Avatar

Well, turns out the rackup file was tampered with! :-/

Avatar

Ryan,

I followed these directions exactly but when I visit http://[ip] I get "Not Found: /". However, when I visit http://[ip]/[appname] it hits the app. Is it possible one of the paths in one of the configs is wrong?

Avatar

Can you try again with RABL 0.6.4 if you get a chance and followup?

Avatar

As kind of an addendum to the link, at the time I wrote that (not too long ago) I saw honestly almost nobody talking about api (json) template building. At least not in my visible sphere.

Things have changed dramatically since then. Now with jbuilder, the revised json_builder, serializers, boxer, et al it seems that this space has gotten a lot of attention recently especially with the rise of Backbone. I consider this a very good thing. I think every api templater that has popped up has a valid use case and an interesting use case. Down with to_json :P

Avatar

Yes personally using RABL with Backbone (or Spine) and also with https://github.com/gazay/gon has made for a great combination for my projects. Anyone reading this might find https://github.com/nesquena/rabl/wiki/Backbone-Integration and https://github.com/nesquena/rabl/wiki/Flexible-Responses useful as well.

Avatar

Great episode Ryan. My only question was is there a reason you used rbenv over rvm to install ruby? Has rvm fallen out of favor? Are you using rbenv on OS X?

Avatar

Is there a way to display just the checkbox instead of a word ?

Avatar

Does anyone have a good css snippet for vertical-aligning the label in the middle of a text area?

Avatar

running postgresql fails. see error

error code
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LC_CTYPE = "et_EE.UTF-8",
        LANG = "et_EE.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
could not change directory to "/root"
psql: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Avatar

Having the exact same issue... did you resolve this?

Avatar

Troubleshooting tip:

If your cap deploy is failing, and you're logging into your server to troubleshoot manually, when you ssh to the server, if Agent forwarding is not already configured by default on your local machine, you'll need to enable it so you can communicate with github:

instead of:

ssh deployer@your-server.com

use:

ssh -A deployer@your-server.com

Avatar

would love to see this updated for Rails 3 with asset pipeline and coffeescript. Or what's the current recommendation for js unit testing with rails?

Avatar

Which log have you looked at? You probably want to check your unicorn/production logs

Avatar

One answer: pull unicorn_init.sh out of source control and put it in the #{shared_path}/config/ directory and symlink to it like database.yml.

Avatar

Another odd thing, the generated application.js seemed to be escaping the '/' with '//' I had to manually fix that. HTH someone.

Avatar

I seem to be having issues, I am getting
Error: Parse error on line 2: Unexpected 'INDENT'
...raffler/app/assets/templates/entries/index.jst.eco)

I literally cut and paste the code in. Using rails 3.2.2, coffee-rails 3.2.2 I must say I am beginning to despair if it takes 4+ hours to get Hello World working with a railscast that is less than 30 days old

Raffler

<% for entry in @entries.models: %>
<%= entry.get('name') %>
<% end %>

Avatar

I seem to be having issues, I am getting
Error: Parse error on line 2: Unexpected 'INDENT'
...raffler/app/assets/templates/entries/index.jst.eco)

I literally cut and paste the code in. Using rails 3.2.2, coffee-rails 3.2.2 I must say I am beginning to despair if it takes 4+ hours to get Hello World working with a railscast that is less than 30 days old

Raffler

<% for entry in @entries.models: %>
<%= entry.get('name') %>
<% end %>

Avatar

How would you deploy to multiple stage environments with your unicorn configuration? Specifically, how to you change:

config/unicorn_init.sh
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E staging"

to

config/unicorn_init.sh
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"

when you run cap staging deploy or cap production deploy, respectively?

Avatar

I'd also like to add my support for a follow up episode that covers cancellations, insufficient funds etc

Avatar

I completely agree with you. This breaks MVC and should not be used. A pity, since I like the idea -- just not the execution.

Avatar

This screencast is brilliant -- much needed by many (obviously, from the comments!), and good to have out there.

I am a big fan of running the app as a special user, rather than root, so glad to see that.

It's also funny -- I love the occasional remarks like "this probably won't work the first time" for Capistrano. Understatement is the best form of humor ;-)

Finally a vote for a fantastic VPS host I have used since 2006 -- RimuHosting has great prices, many options, and best of all, really competent people to help when things go wrong.

Avatar

Figured out a way from your recent post on Capistrano using Multistage-extension. thnx for that one.

Avatar

I found solution, it's simply:

....
<% calendar_for @articles, :year => @date.year, :month => @date.month, :first_day_of_week => 1 do |calendar| %>
...

thanks to all

Avatar

Luis Pablo or anybody else:
Could you please post some example code in more detail. I´m new to Rails and don´t get it working. Don´t know in which controller to write the join and so on :-(

Maybe someone can post the exact steps for jayeshmori´s example with the video and category?

Hope someone can help!

Avatar

How to sort days in calendar table such as <%= calendar.head('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')%> with correct order of day? I want to make Monday the first day of the week.
please help me!

Avatar

Thanks for this ryan, amazing as always!
I used this with Kaminari along with using a script to see if the pagination links are in the window view area (since I was working with a table that is in the middle of the page)
Coffee Script below:

javascript
jQuery ->
        isScrolledIntoView = (elem) ->
                docViewTop = $(window).scrollTop()
                docViewBottom = docViewTop + $(window).height()
                elemTop = $(elem).offset().top
                elemBottom = elemTop + $(elem).height()
                (elemTop >= docViewTop) && (elemTop <= docViewBottom)

        if $('.pagination').length
                $(window).scroll ->
                        url = $('.pagination .next_page a').attr('href')
                        if url && isScrolledIntoView('.pagination')
                                $('.pagination').text('Fetching more...')
                                $.getScript(url)
                
                $(window).scroll()

And in the index.js.erb file:

javascript
$('#all_pages').append('<%= j render(@pages) %>');
<% if (@pages.current_page < @pages.num_pages) %>
        $('.pagination').replaceWith('<%= j paginate(@pages) %>');
<% else %>
        $('.pagination').remove();
<% end %>

I used @pages.current_page < @pages.num_pages since I couldn't get the @pages.next? method working with collections. Hopefully it will work in a future release.

Avatar

Anyone experienced an issue when running rvmsudo, that the script hangs at a password prompt that can not be entered?

ruby
Lets say this task: 
task :export, :roles => :app do
    run "cd #{release_path} && rvmsudo bundle exec foreman export upstart"
 end

Then rvmsudo will hang at [sudo] password for, you wont be able to enter a password.

I solved this issue by executing a random sudo command in front of the rvmsudo command.. For example sudo "whoami". But i wonder if there is a clean solution.

Also anyone experienced an issue that they can not restart their services trough rvmsudo? For example rvmsudo restart #{application}" throws /usr/bin/env: restart: No such file or directory

Avatar

There is a simple fix for this: Just use a pinging service that pings the site every minute or so. I do this with new relic. And voila, your app doesn't fall asleep anymore.

Avatar

Yes you can overwrite the find_one method. Look at https://github.com/norman/friendly_id/issues/197 for an example.

But make sure that you are starting with the right finder method, eg history uses another one.