Hi,
In Rails 3, if you are failing validations due to validating the parent_id in the child model when parent.new_record? and therefore parent is not yet saved, here's a solution.
I tried to retrieve user email which signed in with Facebook, but it wasn't available throw omniauth['user_info']['email'], but on omniauth['extra']['user_hash']['email']
Is this normal ?
First of all congrats for this great community and work is really satisfactory see so much help.
Second, I have read that if you have included accessor methods to your fields (attr_accessible and/or attr_protected) you have to define the attr_writer, is there any example with this due to I'm not understanding how to implementing it.
@Steve Castaneda, I bet the best way to revert recursive removals fromoutside thegem would be to store the class name and the ids of the children into the metadata of the destroyed object, and recall them on restore.
@Ryan, thanks for this -- a far neater implementation of undo than in my own apps! Also, using `scoped` is a good trick.
@Steve, automatically bringing back dependent associations is something I haven't cracked yet. I've tried a couple of times but so far haven't come up with code I like. All patches welcome.
@4ware, Paper Trail is only available for Active Record, there is mention of adding Mongoid support here: https://github.com/airblade/paper_trail/issues#issue/35
@Steve, I haven't tested this with associations yet, but try adding has_paper_trail to both models and see if it brings back the association. If that doesn't work, I know Vestal Versions has a ":tracking" option for this, so you may want to use that if you need this functionality.
@otagi, right, you would only want to add this where it works well.
@/users/1021, yes, but they can also edit other models by guessing their ids. If you are restricting permissions in the resource controller, you will also need to restrict them in the versions controller. You may want to use CanCan for this so the permissions are all in one place.
@Javi, thanks for the info. I didn't realize Vestal Versions allowed deleting of older records.
I've been using both Paper Trail and Vestal Versions for this kind of things.
I've found Paper Trail to be more complete, and with many convenient methods such as "next", as you show. Another point is that it seems to be more actively mantained.
But I prefer Vestal Versions philosophy of storing the current version when you update a record (Paper Trail stores the previous one on an update). That way the current version can easily be managed with all the rest in features such as wiki-like history and comparison.
And you actually can delete old versions with Vestal Versions. Vestal Versions recovers previous versions based on differences with the current one, so deleting old ones doesn't hurt a bit either.
Only watching your casts is enough for using Rails :). Thanks to your effort. For me destroy link has to be changed on Rails. Because records must not be destroyable as default.
I downloaded the code for the app and I'm having trouble trying to run it in Win 7 (FireFox and Chrome).
The app runs only if the server is running, otherwise I ger an "Unable to Connect". I'm running Rails 3.0.3 and ruby 1.9.2p0.
Small gotcha if anyone gets caught up on this...if you are attempting to paginate an ActiveRecord relation that has had the includes method called on it, and you include another table with a column name that is the same as the table you're paginating (like created_at), and you're trying to order on that column, kaminari can't figure it out.
You have to do something like this:
@posts = Post.order("posts.created_at DESC").page(params[:page]).per(5).includes(:comments)
This feature is a replacement of pseudo_cursors. I just found out after some errors when migrating to Rails 2.3
Hi,
In Rails 3, if you are failing validations due to validating the parent_id in the child model when parent.new_record? and therefore parent is not yet saved, here's a solution.
http://stackoverflow.com/questions/2102724/rails-nested-attributes-association-validation-failing
I tried to retrieve user email which signed in with Facebook, but it wasn't available throw omniauth['user_info']['email'], but on omniauth['extra']['user_hash']['email']
Is this normal ?
The only problem I found is that params[:page] is not set to 1 for page one and defaults to nil.
Hi everyone,
First of all congrats for this great community and work is really satisfactory see so much help.
Second, I have read that if you have included accessor methods to your fields (attr_accessible and/or attr_protected) you have to define the attr_writer, is there any example with this due to I'm not understanding how to implementing it.
Kind regards.
I'm also wondering if Kaminari will work with meta_search. Will poke at it and see
Check out my fork here: https://github.com/maletor/paper_trail
Also, vestal_versions is better.
@Steve Castaneda, I bet the best way to revert recursive removals fromoutside thegem would be to store the class name and the ids of the children into the metadata of the destroyed object, and recall them on restore.
@Ryan, thanks for this -- a far neater implementation of undo than in my own apps! Also, using `scoped` is a good trick.
@Steve, automatically bringing back dependent associations is something I haven't cracked yet. I've tried a couple of times but so far haven't come up with code I like. All patches welcome.
@4ware, Paper Trail is only available for Active Record, there is mention of adding Mongoid support here: https://github.com/airblade/paper_trail/issues#issue/35
@Steve, I haven't tested this with associations yet, but try adding has_paper_trail to both models and see if it brings back the association. If that doesn't work, I know Vestal Versions has a ":tracking" option for this, so you may want to use that if you need this functionality.
@otagi, right, you would only want to add this where it works well.
@/users/1021, yes, but they can also edit other models by guessing their ids. If you are restricting permissions in the resource controller, you will also need to restrict them in the versions controller. You may want to use CanCan for this so the permissions are all in one place.
@Javi, thanks for the info. I didn't realize Vestal Versions allowed deleting of older records.
I've been using both Paper Trail and Vestal Versions for this kind of things.
I've found Paper Trail to be more complete, and with many convenient methods such as "next", as you show. Another point is that it seems to be more actively mantained.
But I prefer Vestal Versions philosophy of storing the current version when you update a record (Paper Trail stores the previous one on an update). That way the current version can easily be managed with all the rest in features such as wiki-like history and comparison.
And you actually can delete old versions with Vestal Versions. Vestal Versions recovers previous versions based on differences with the current one, so deleting old ones doesn't hurt a bit either.
it seems as if another (malicious) user could revert an action by poking around using different (guessed) :ids, couldn't they?
Great screencast as always.
Confirmation boxes are still useful, though. Undoing changes on a model with a Paperclip attachment is less trivial.
Love it! Only one question: how will this work for database records that are deleted through :dependent => :destroy?
So if a post :has_many comments, and I delete a post, wouldn't the .last parament get the last comment of that post and allow me to revert that only?
I guess I'd need to add more logic to the revert method for this then.
Thanks Ryan, excellent screencast on a very useful topic.
Does anyone see a problem integrating this gem with mongoid?
Only watching your casts is enough for using Rails :). Thanks to your effort. For me destroy link has to be changed on Rails. Because records must not be destroyable as default.
That was great Ryan. I will implement this gradually to all my projects starting today.
How would I add a restriction on the file size?
Great tutorial thanks a lot!
I just had one "bug": I had to add manually
resources :articles do
resources :comments
end
in my routes files. I'm new to rails and I struggle a little to understand the way routes works but this solved it for me.
How would I use a custom scope within default_scope?
(if the user is logged in, show inactive stuff if not only the active stuff)
This is what I'm trying to do ...
https://gist.github.com/844917
hope someone can shed some light on this.
Thanks,
Matenia
How can I render page_duration time in my layout?
I downloaded the code for the app and I'm having trouble trying to run it in Win 7 (FireFox and Chrome).
The app runs only if the server is running, otherwise I ger an "Unable to Connect". I'm running Rails 3.0.3 and ruby 1.9.2p0.
ah yes, I also support the "Remember me" suggestion
I wonder why some users show up with their user name, but some as "/users/123"... is it something with the field name...?
Since you have Railscasts for JanRain or OpenID Selector, would you like to add that to the log in system here?
nice video. Can you add some details if incorrect username or password is entered, instead of persisting, can it
1) show a page with Unauthorized: incorrect username or password
2) or somehow indicate wrong username or password and let the user try again
3) either (1) or (2) above after 3 attempts to log in but fail.
#fail i used this gem and nothing return all objects exist in my database!
Small gotcha if anyone gets caught up on this...if you are attempting to paginate an ActiveRecord relation that has had the includes method called on it, and you include another table with a column name that is the same as the table you're paginating (like created_at), and you're trying to order on that column, kaminari can't figure it out.
You have to do something like this:
@posts = Post.order("posts.created_at DESC").page(params[:page]).per(5).includes(:comments)
Can you use an image link instead of Previous or next
Adding kaminari to my Gemfile has stopped pickle steps being recognised by cucumber. Anyone else noticed this?
Enjoyed the screencast very much. Do more of these :)
nice) it works on my site!
does it work with datamapper?
@20 Just released 0.10.3 gem that can hopefully handle group query. https://github.com/amatsuda/kaminari/commit/1de679
Could you update your gem and try again?
Thanks!
Hi there, did you get kaminari to work with meta_search results?
@23
Sorry but i don't know what you mean. Could you please explain it or give me a example? -Thx
By the way, adding
config.rcov[:rcov_opts] << "-Itest"
to MetricFu::Configuration got rcov working
Akira Matsuda and Ryan, thanx guys!!
@20
a groupby result is not paginatable, because the result is a key value response.
u must use subselects like:
where("id IN (YOUR SELECT)")
i think kaminari has to much views.
i have build my own paginator, that not need so much views. it use only ul/li's with good css class for styling or hidding.
https://github.com/phatworx/rails_paginate
I'm sorry I forgot to mention how to.
<%= paginate @products, :param_name => :pagina %>
Enjoy!
@ryanb Thank you for introducing Kaminari!
@Allen @Nico @Branden Just added that feature and released a new version. Can you try out 0.10.2 gem? Thank you very much @Allen for you cooperation!
@Tilo Great tip! I shall write that on my Wiki.
you read my mind with this railscast - was looking for something like this
Agreed Allen,
That's a primary function in an application I've built. I wonder if that is something they plan on adding in the future.
Good find! Thank you!
I love that it uses HTML5 tags, e.g. <nav>
Some browsers don't understand HTML5 tags yes, e.g. Firefox <= 3.6
To work around this, tell the browser which new tags are blocks:
header, footer, nav, article, section, aside { display: block; }
@Nico Ritsche
I know uploadify (and swfupload, pupload...) the difficult is to integrate with rails !
Why this is better than will_paginate?
thank you once again!