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 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
defself.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
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.
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.
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!
"...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..."
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.
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.
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.
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?
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.
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
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
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.
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?
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?
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. :-)
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:
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?
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.
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.rbhttps://github.com/karmi/railscasts-episodes/compare/master
You are a life saver Ryan. This episodes are golden.
Thank you.
Already solved :)
Hi binaryx,
try the reputation-system-from-scratch. I got this to work with will_paginate.
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 theby_votes
class method to solve this. I also had to addgroup
to the query to get more than one haiku. WithoutSUM()
andgroup
I got duplicate haikus.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!
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. ;)
i need to set the border-color dynamically????
i need to set the border-color dynamically????
Also check find_cache gem for thread safe model caching
https://github.com/mustafaturan/find_cache
http://rubygems.org/gems/find_cache
http://rubydoc.info/gems/find_cache/0.1.8/frames
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
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
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!
+1
Greg,
My VPS is now runnig.
I made a list of commands that maybe you will find useful
https://gist.github.com/3701678
thanks for clarifying this
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..."
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.
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.+1!
i have the same error...
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
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.
Add
:password
and:password_confirmation
to Identity model as accessible attributes: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?
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.
You have the following comment in the routes:
Indeed the update and destroy actions don't work on those pages. What is the solution?
+100
@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
I have many price fields (monthly, average, total etc).
Can these getter/setter methods be rewritten for use with all my fields?
Is there a reason why you're using POST for a search form?
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
Was there a solution to this?
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)
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 ?
I cant' turn on stemming:
If somebody searches for 'Caphs' it should find this too: 'Caph\'s'
Doesn anybody know how to do this?
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.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
This brings me great happiness Ryan... very great happiness...
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?
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?
yes, please do. sqlite + pg means sqlite is not profiled
yep i noticed the same problem, wonder why the default nginx install has that issue.
Anyways your fix worked.
Thanks
hey guys tried the guide again and i am again getting the following error:
any ideas?
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!
thanks for the tip! Also works nicely in Sublime Text 2
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. :-)
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
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!