RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

has anyone come across conflict with object based authorization and strong-parameters?

I use declarative-auth, I believe cancan also does this, where they will load the object before getting to the :create action. The problem is, I get the ActiveModel::ForbiddenAttributes when submitting to create - since the auth layer is doing the SomeObject.new call without the "permitted_params.some_object".

I suppose monkey-patching the gem is best idea.

Avatar

Check out the diff between ryan's and karmi's code (linked above in the comments) for some ideas on this. Look at the :author index in article.rb
https://github.com/karmi/railscasts-episodes/compare/master

Avatar

You are a life saver Ryan. This episodes are golden.

Thank you.

Avatar

Hi binaryx,

try the reputation-system-from-scratch. I got this to work with will_paginate.

Avatar

Hi Ryan,

I had a problem with your reputation-system-from-scratch, that all haikus with more than one vote were ordered as they had only one vote. I added the SUM() function to the by_votes class method to solve this. I also had to add group to the query to get more than one haiku. Without SUM() and group I got duplicate haikus.

ruby
def self.by_votes
  select('haikus.*, coalesce(SUM(value), 0) as votes').
  joins('left join haiku_votes on haiku_id=haikus.id').
  group('haikus.id').
  order('votes desc')
end
Avatar

Ryan, is that a video rendering error at the end where you try to switch to "/-l" in vim? It looks like the video lags for a while.

Other than that, very nice intro to dalli!

Avatar

Thanks Ryan!

I'm surprised you didn't show the russian dolls technique as exposed by 37signals few months ago (http://37signals.com/svn/posts/3113-how-key-based-cache-expiration-works).

It's a great video anyway, as always. ;)

Avatar

i need to set the border-color dynamically????

Avatar

i need to set the border-color dynamically????

Avatar

Nice RailsCast Ryan. Are you aware of any good write through caches for models. I'm aware of CacheMoney but it seems to be somewhat defunct for use with Rails 3.

Cheers
Paul

Avatar

I am having trouble with doing errors(:base) << message. Could someone please look at my post and see if they could help me out: http://bit.ly/OFthci

Thank you

Avatar

I encountered a few issues using paperclip 3.2.0.

When using the after_update callback to update the images, it ran into an infinite loop, since paperclip updates the avatar_updated_at column on the model after it completes the crop, so the model gets updated again and re-kicks off the callback.

To resolve this I called @user.avatar.reprocess! directly in the controller if cropping.

Reference Thread: https://github.com/thoughtbot/paperclip/issues/866

I also had some issues with the Cropper Processor in this cast, so I used the code from here: http://viget.com/extend/manual-cropping-with-paperclip

Also, I created a crop_box style, which I explicitly exclude from my cropping processor, so that I can display an unaltered 250x250 image so the user can continually go back and edit their "original" image, and the cropping only applies to thumb nails and medium images. I simply did that by wrapping the logic in transformation_command with:

def transformation_command
if target.cropping? && ![CROP_BOX_PAPERCLIP_STYLE].include?(options[:geometry])
....
else
super
end
end

I declared CROP_BOX_PAPERCLIP_STYLE in environment.rb so that it is available across my application.

It does force me to give crop_box a very unique size so it wont bump into other styles I have!

Good luck and thanks for the cast!

Avatar

Greg,

My VPS is now runnig.
I made a list of commands that maybe you will find useful

https://gist.github.com/3701678

Avatar

Ryan explains...

"...This works well but if the user adds too many conditions they might run into the limit of the data that can be sent over a GET request. One way around this problem is to use POST instead so we’ll implement this..."

Avatar

I've played a lot with OmniAuth Identity, and in the end for the little it provides, I don't think it's worthwhile.

I found that after having to override it's views, and having to add password recovery, authentication redirection and session remember me functionality myself, I may as well just use Rails 3's has_secure_password myself. I've ditched OmniAuth Identity in favor of Rails built-in has_secure_password, and I'm much happier and find it's much cleaner and nothing is abstracted away.

Avatar

Why would you make the :password_digest accessible? The :password and :password_confirmation are the only password attributes that should be accessible. If you open up the :password_digest you just compromised your security model.

Avatar

I ran in to the following problem: "ERROR: Could not start Spork server for Test::Unit & RSpec".

To fix this issue I added the following to my Guardfile.

guard 'spork', :test_unit => false, :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do

Avatar

The choice of whether using a cms/dynamic approach or a static
implementation is more a question of how often the content is supposed to change and how the process of this change is implemented, rather than how many static files the project contains.
One should not forget the massive performance difference between
these two approaches.

Avatar

Add :password and :password_confirmation to Identity model as accessible attributes:

app/models/identity.rb
class Identity < OmniAuth::Identity::Models::ActiveRecord
  attr_accessible :email, :name, :password_digest, :password, :password_confirmation
  # ...
end
Avatar

Awesome screencast! I've used this multiple times for reference and works great. However, I recently tried following this example, but instead of installing rbenv I had to use rvm. And when I get to the point of running 'cap deploy:cold' I keep getting the following error: sh: 1: bundle: not found. I installed bundler correctly and confirmed it by running 'bundle -v'. One thing I did notice in previous apps when following this tutorial (when using rbenv) that under my_app_directory/shared there would be a bundle/ directory, however now that directory doesn't exist, so maybe that is the 'bundle not found'? Any ideas?

Avatar

I tried restarting Unicorn and nginx hoping Unicorn will notice the new gems, but it wouldn't work. It seems that you have to STOP unicorn, then START it again, it worked for me.

Avatar

You have the following comment in the routes:

if you want the update/destroy actions to work you may want to use a different name for this route.

Indeed the update and destroy actions don't work on those pages. What is the solution?

Avatar

@Matthew Ford(Im sure you found this by now)

For anyone who followed the rails api gem cast you might have problems adding in the:

"authenticate_or_request_with_http_token"

To use this you will need to add this line:

include ActionController::HttpAuthentication::Token::ControllerMethods

Avatar

I have many price fields (monthly, average, total etc).

Can these getter/setter methods be rewritten for use with all my fields?

Avatar

Is there a reason why you're using POST for a search form?

Avatar

Found the error was in the profiler.rb script where there was a parameter after the optional parameter which was required when it should be optional as well with an = nil

Avatar

Hi I am getting the following error when starting rails server after installing the gem using bundle install. Has anyone seen this and know how to resolve it. I am using ruby 1.8.7 and rails 3.2

ankur@ankurmac ~/D/c/b/openslot> rails s
/Users/ankur/.rvm/gems/ruby-1.8.7-p370/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:251:in `require': /Users/ankur/.rvm/gems/ruby-1.8.7-p370/gems/rack-mini-profiler-0.1.18/lib/mini_profiler/profiler.rb:375: syntax error, unexpected ')', expecting '=' (SyntaxError)

Avatar

Hi, monit doesn't want to monitor workers, that's very strange, my app is working and if I do ps aux | grep unicorn I can see them :

deployer 19705 1.7 10.0 59404 50972 ? Sl 02:59 0:06 unicorn master -D -c /home/deployer/apps/blog/shared/config/unicorn.rb -E production

deployer 19709 0.0 10.5 65484 53848 ? Sl 02:59 0:00 unicorn worker[0] -D -c /home/deployer/apps/blog/shared/config/unicorn.rb -E production

deployer 19712 0.0 10.5 65484 53824 ? Sl 02:59 0:00 unicorn worker[1] -D -c /home/deployer/apps/blog/shared/config/unicorn.rb -E production

However /home/deployer/apps/blog/shared/pids contains only unicorn.pid and no unicorn.0.pid

Also if I try to find them with find (sudo find / -name "*.pid") :

/home/deployer/apps/blog/shared/pids/unicorn.pid
/run/monit.pid
/run/nginx.pid
/run/ntpd.pid
/run/sshd.pid
/run/fail2ban/fail2ban.pid
/run/upstart-udev-bridge.pid
/run/atd.pid
/run/crond.pid
/run/rsyslogd.pid
/run/dhclient.eth0.pid
/run/upstart-socket-bridge.pid

Only the master appears...

Do you have any idea about it plz ?

Avatar

I cant' turn on stemming:
If somebody searches for 'Caphs' it should find this too: 'Caph\'s'
Doesn anybody know how to do this?

Avatar

My guess is you are probably not using your id_rsa.pub key for the remote git repo. I had a different key set for a repo and got the same error. All I did was add my id_rsa.pub key to the remote git repo and everything worked fine. I think there is a way to also do ssh-add, but I was less than successful with getting that to work.

Avatar

Use visudo and edit the sudoers file. Make sure the admin or sudo group, which ever your deploy user is in, has the NOPASSWD option:

%sudo ALL=(ALL) NOPASSWD:ALL

Avatar

This brings me great happiness Ryan... very great happiness...

Avatar

Thanks Ryan. I'm a new one so permit me to imagine:
Ruby is excellent for oo( object oriented) language. With oo db,such as mongodb, programming will be much more productive.
I love rails, but I think his power is in activerecord. Since relation db is obsolete, rails' value is limited. So
{new :old}
ruby/javascript :java
mongodb :mysql
json :xml
(things like)BB :rails
REST:SOAP
Is my understanding right?

Avatar

Does anyone know if / how / links to an API or such that will allow me to pull for instance just one graph into my Rails app, for example for showing number of visits to a user's page on that user's dashboard?

Avatar

yes, please do. sqlite + pg means sqlite is not profiled

Avatar

yep i noticed the same problem, wonder why the default nginx install has that issue.

Anyways your fix worked.

Thanks

Avatar

hey guys tried the guide again and i am again getting the following error:

fighterpilot@JJDRORPROD01:~/jjdowns$ cap deploy:cold
  * executing `deploy:cold'
  * executing `deploy:update'
 ** transaction: start
  * executing `deploy:update_code'
    updating the cached checkout on all servers
    executing locally: "git ls-remote gitolite@10.0.14.14:jjdowns master"
    command finished in 166ms
  * executing "if [ -d /home/fighterpilot/jjdowns/shared/cached-copy ]; then cd /home/fighterpilot/jjdowns/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard 019cbef11c95698d7e8e7788e04fd77d07c47ae7 && git clean -q -d -x -f; else git clone -q gitolite@10.0.14.14:jjdowns /home/fighterpilot/jjdowns/shared/cached-copy && cd /home/fighterpilot/jjdowns/shared/cached-copy && git checkout -q -b deploy 019cbef11c95698d7e8e7788e04fd77d07c47ae7; fi"
    servers: ["10.0.14.17"]
    [10.0.14.17] executing command
 ** [10.0.14.17 :: out] Error writing to authentication socket.
 ** [10.0.14.17 :: out] Error writing to authentication socket.
    command finished in 1111ms
    copying the cached version to /home/fighterpilot/jjdowns/releases/20120909041546
  * executing "cp -RPp /home/fighterpilot/jjdowns/shared/cached-copy /home/fighterpilot/jjdowns/releases/20120909041546 && (echo 019cbef11c95698d7e8e7788e04fd77d07c47ae7 > /home/fighterpilot/jjdowns/releases/20120909041546/REVISION)"
    servers: ["10.0.14.17"]
    [10.0.14.17] executing command
 ** [out :: 10.0.14.17] cp: cannot create directory `/home/fighterpilot/jjdowns/releases/20120909041546': Permission denied
    command finished in 141ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /home/fighterpilot/jjdowns/releases/20120909041546; true"
    servers: ["10.0.14.17"]
    [10.0.14.17] executing command
    command finished in 140ms
failed: "sh -c 'cp -RPp /home/fighterpilot/jjdowns/shared/cached-copy /home/fighterpilot/jjdowns/releases/20120909041546 && (echo 019cbef11c95698d7e8e7788e04fd77d07c47ae7 > /home/fighterpilot/jjdowns/releases/20120909041546/REVISION)'" on 10.0.14.17
fighterpilot@JJDRORPROD01:~/jjdowns$ 

any ideas?

Avatar

Ryan, your approach with truly nested templates for JSON nicely circumvents some problems I've encountered with RABL.

This can also be used to extract a JSON paginator into a template which can then be used across different models.

Thank you, Ryan for this awesome Railscast!

Avatar

thanks for the tip! Also works nicely in Sublime Text 2

Avatar

Ryan, I assume you used iTerm2 before you switched back to the OSX Terminal? If so, this option for preserving the directory you were in, can be done in iTerm2 also, it's in Preferences - Profile - General - Working Directory - Advanced Configuration (There I set it to $HOME when opening new windows and to the previous sessions directory on new tabs and split panes. :-)

Avatar

I was also finding problems making Pigments work from within redcarpet. I finally opted for Coderay, as on the original version of this railscasts, here's what I did:

How to colorize code in comments using CodeRay

Avatar

Thank you for doing RailsCasts and offering a pro subscription reasonably. May I ask if you could make a video about code formatting within either a template or on a page. Like the way GitHub or GitGist formats code?

Or the way you're doing it on your own site!