RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

In addition to this, does anyone know how we can authorise child objects based on an association of the parent? I also posted about this here:

http://stackoverflow.com/questions/12885246/authorising-child-objects-through-a-parents-association-using-cancan

The docs breifly discuss this under "Accessing parent ability" (https://github.com/ryanb/cancan/wiki/Nested-Resources) but no mention of associations is made.

Avatar

I use the JQuery file upload (but just allowing one file to be selected). If the file is just part of a object, say user. So the user can upload a single picture to the user object. I don't want to create a new record when a file is uploaded, simply update a field. How does one accomplish that?

Avatar

You can setup EC2 instance or stick with carrierwave?
Ryan ... come on man ... how??, that's the question!!!

greetings from Palestine <3

Avatar

Hi guys,

I'm following the tutorial, but I'm blocked to the migration which doesn't work.

terminal
==  AddTranslationsToEventCategory: migrating =================================
rake aborted!
An error has occurred, this and all later migrations canceled:

PG::Error: ERROR:  relation "translations" does not exist
LINE 4:              WHERE a.attrelid = '"translations"'::regclass
                                        ^
:             SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
              FROM pg_attribute a LEFT JOIN pg_attrdef d
                ON a.attrelid = d.adrelid AND a.attnum = d.adnum
             WHERE a.attrelid = '"translations"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum

I've created a question on StackOverflow, but haven't any clue yet.

I wonder if anyone can help me solving this issue. My code is here

Thanks in advance

Avatar

Can you elaborate on what you mean by n+1 problems?

Avatar

For accessing the total number of votes for a haiku, we need to use haiku.reputation_for(:votes) instead of haiku.reputation_value_for(:votes).

Avatar

We forked this railscast project and re-implemented it using the versioncake gem. Any comments would be appreciated!

https://github.com/bwillis/350-rest-api-versioning

Avatar

We are working with a similar approach. I agree that ideally we should focus on payload changes. Check out the versioncake gem: https://github.com/bwillis/versioncake

Avatar

Hey guys,

I have some Javascript validations for the dynamic fields, how do you go about solving the issue with dynamically inserted fields? This gem generates the current datestamp.

Avatar

Is there a way to whitelist for any actions within a controller using this method?

In the method you suggested in part 1, we did this:

ruby
return true if controller == "pages"
Avatar

I monkey patched it as stated above... there may be a better solution but on the controller i threw a public method call new_#{controller.to_s.singularize}_from_params. There may be a better way to do this than on each controller but my code for a topic would look like this

ruby
def new_topic_from_params
  @topic = Topic.new(permitted_params.topic)
end

Then just do all your normal stuff in the create method. This method should pass it along. Hope it helps someone!

Avatar

Great stuff Ryan.

I hit a problem with the overridden - in /config/initializers/scope_operators.rb though. It conflicts with
activerecord-3.2.8/lib/active_record/associations/collection_association.rb:479

unless concat(new_target - target)

The minus operator fires the not() method defined in scope_operators.rb. Removing the alias made it happy again.

Avatar

do you know how to solve these problem ..I searched a lot with no answer
/etc/init.d/unicorn_depot_2: Permission denied

Avatar

Hi all,

Running cap rubber:create_staging

I get this error:

Missing rule, creating: {"source_group_name"=>"blog_production_default", "source_group_account"=>"1072835180", "protocol"=>"tcp", "from_port"=>"1", "to_port"=>"65535"}
[DEPRECATION] 'account:group' argument is deprecated. Use {account => group} or just group instead
/home/user/.rvm/gems/ruby-1.9.3-p194/gems/excon-0.16.4/lib/excon/connection.rb:290:in `request_kernel': The security group 'blog_production_default' does not exist (Fog::Compute::AWS::NotFound)

Does anybody know whats going on?

Thanks!.

Avatar

I got some probems with my .js file can you please explain it on rails 3.2

Avatar

Which is considered "best practice"
1. Returning the partial via javascript (.js.erb) OR
2. Using an ajax call back function to update the page on success or failure
Thank you for your comments.

Avatar

Are there any gotcha for using authorize_resource as opposed to load and authorize_resource? I'm getting different behaviour, where load and authorize works, but authorize does not prevent access to a resouce.

I posted a question on this: http://stackoverflow.com/questions/12860146/cancan-not-preventing-access-when-it-should

I have no clue why this is behaving in such a way!

Avatar

how can I combine edit, show, destroy button to one column.

Avatar

Likewise, any advice on this front would be warmly received.

Avatar

Very nice! Especially liked that it was all done with testing.

Not sure that I like putting permissions definitions into separate files though. I would expect to see those directly in controllers and models defined with class method calls. The same way as attr_accessible is used - right from the model - for example. But maybe I just don't see all the benefits of using separate files yet, need to play with the code first I guess. Or maybe it's just a matter of taste :)

Anyway, great learning material!

Avatar

In regards to the use of Array(controllers) to enumerate over potentially singular things, I have been using another technique I saw at http://www.rubyinside.com/21-ruby-tricks-902.html #18: [*controllers].each... Is there anything wrong with that form that I don't know about?

Avatar

just modify your codeline

user.oauth_expires_at = Time.at(auth.credentials.expires_at)

also to a single line:

user.oauth_expires_at = Time.at(auth.credentials.expires_at) unless auth.credentials.expires_at.nil?

@cbmeeks thank you!

Avatar

Ah @Dom so I guess all the things Ryan points out in the video still haven't been added to Omniauth Identity since Dec 2011? I was assuming a number of them had probably been added since then.

Hmmm. In your opinion, would it be worth (me, or someone) adding them--in the spirit of open-source--to the OmniAuth Identity code, for everyone to use, or is it--in your opinion--just a fundamental problem over has_secure_password and probably isn't the right way to build support for something like this?

(Background: I'm mostly interested in building a internal, shared login solution (SSO) for all app services/assets in-house that will use Rails to login via a centralized login service--that we'll build. We may also provide FB/OpenID etc. auth, too, but that's not the main goal. It's mainly a 'separable' login service in-house for all our devs to use.)

Avatar

@jleecbd have you figured out any more regarding the questions you ask here--I'm interested in similar topics.

Also, when you say (to Ryan) "previously you made all Omniauth authentication options exist" which RailsCast are you referring to? I'm interested in which one you mean.

Thanks
~ Brad

Avatar

it is not working for me as well..
I get the error:

PGError: ERROR: column "tags.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT tags.*, count(taggings.tag_id) as count FROM "tags" I...

Can anyone help with that?

Avatar

I think I may be having the same problem. However, I'm not sure, because when I use:

params.require(:user).permit!

it works just fine. But, when I use:

params.permit(user:[:password,:password_confirmation,:current_password)

it gives the ActiveModel::ForbiddenAttributes exception.

Avatar

Hey Wayne, very helpful. Do you know if your gem IE8/9 compatible?

Avatar

I've implemented something like this. I'm curious if anyone has had any luck getting it to work on IE8/9?

Avatar

simple_form does not allow all bootstrap classes.

Avatar

This was extremely helpful, @Pranay. Thanks!

Avatar

I'm wondering like @swrobel how we can incorporate fragment caching?

Avatar

Hi.all :)

Does anyone know how to deploy this project on Heroku?

Thanks in advance!

Avatar

Calling Thread.new every time you need to do something async could create more threads then you probably want. Besides that, using sidekiq you can have a dedicated machine just to process the queues.

Avatar

Did you see turbolinks? Looks like you are developing the same thing.

Avatar

I'm struggling also with the point of limiting the predicates to some possibilities.

I tried out:

_condition_fields.html.erb
<%= f.predicate_select :only => ['eq'] %>

but this didn't work. Unfortunately, the documentation seems not to help.

Avatar

Knight's Spreadsheets (Ruby) section compiles a list of gems that can help with parsing and writing Spreadsheets and CSV. Knight.io is a gem wiki for developers, a current project of mine.

Avatar

Virtual attributes don't activate callback functions in Rails 3.2.8

Avatar

'libmagick9-dev' is no longer available, adding 'imagemagick, libmagickwand-dev' to packages: in rubber.yml is worked for me.

Avatar

Damien, that is a valid question. A potential answer might be that Ryan was merely using those share icons as an arbitrary and easy-to-grasp example. But, he may have left them not-sprited on this site for accessibility reasons; images that have a function (merely than just aeshtetic) have the crucial alt attribute for screen-readers and when an image is broken or not loading for whatever reason.

If you Google search for something like "css sprites alt accessibility" you'll find plenty of arguments for what best practices are when it comes to Spriting, but the consensus seems to be "don't Sprite everything" as well as numerous different approaches to hacking emulation of alt tags.

Avatar

Tempting for me to point out the allowy gem.

The implementation is very similar to what has been shown in this screencast.
Very lightweight, inspired by CanCan.

Even though it doesn't have much activity it is being used in production heavily (so sometimes project can be "finished" :) )

Avatar

After deploying in production it gave a 'Bad Gateway' error in browser. The corresponding error in the nginx error.log was "upstream prematurely closed connection while reading response header from upstream, client:" Any Ideas?

Avatar

Sadly, that is only available to 1.7+

Avatar

Kind of a noob question here, but when Ryan moves the javascript into $(function() { }, why does this fix that issue? Would using the standard $(document).ready() not do the same thing?

Avatar

I noticed that remote_image_url downloads the image from the remote server[S3] and the save method re-upload the images.

The implication of that:
If the server downloads the image and re-uploads it again, We did not spare anything.

Is there a way to upload just the process image (like the thumbnails) and not re-upload the source image?