@Jelkster Totally! I've been watching Railscasts since 2007 and I've learned so much from them. I'm happy to be giving back now. Keep up the awesome work, Ryan!
This is great! So I created a model and I am having a separate issue. Since I use the @errors = ActiveModel::Errors.new(self) collection in my initializer and validators, when I generate JSON to store in my NOSQL database, it's including all kinds of stuff that I don't want to store:
{"errors"=>#, @username="jasdeep", @validation_context=nil, @firstname="Jasdeep", @lastname="Jaitla", @messages={}>, "username"=>"jasdeep", "email"=>... and so on
but it has no effect, it still outputs every attribute and object. I have looked EVERYWHERE googling for hours upon hours and still can't find a solution for this.
I've tried overriding as_json in my Model class, but still no effect.
Any help or pointers are appreciated...
class User
include ActiveModel::Validations
include ActiveModel::Conversion
include ActiveModel::Serialization
extend ActiveModel::Callbacks
extend ActiveModel::Naming
I'd also like to add my support for a follow up episode that covers cancellations, insufficient funds etc
Just want to add that it's watching episodes like this that shows what a fantastic Ruby coder you are Ryan! I always pick up some tip or another watching you code :)
"We use update_all here so that all of the updates are made in a single query"
hi Ryan, for me it still issues individual updates for each item in the list. that makes sense since the "update_all" call is inside of the each loop. am i missing something?
p.s. great work on the screencasts, keep 'em coming.
I'm using Stripe to put together a SaaS application. We create a customer (Stripe) and link it to the user (our app). We handle the upgrading, trials, and charging. Just charge expiring customers in our crontab.
Stripe::Charge.create(
:amount => 1500, # $15.00 this time
:currency => "usd",
:customer => current_user.stripe_customer_token
)
solr (sunspot) supports synonyms. It should be easy to set up "mobile phones" and "nokia" as synonyms. I assume conditional logic like returning alcohol or whiskey if beer is not found is a lot more complex. Don't know if solr/lucene can do that out of box.
I've been using solr for a few weeks now and am pleasantly surprised how well it's coming together for our needs.
Excellent. Very clear. Does one really get a great performance gain by just using rack with a bunch of middleware for a simple app? Also, I'm thinking this is just instructive, as sinatra seems to cover most everything with minimal overhead already. Thanks again.
A note to anyone using this gem with seyhunak / twitter-bootstrap-rails gem.
if you use rails g bootstrap:layout to generate your application layout, you will need to go into the layout and take the javascript_include tag out of the very bottom of the layout and move it up to the top of it under the stylesheet_include tag or private_pub will not work!
I used Valuable gem to implement something similar to activeattr with type and default. I'm using it with redis for persistence and it's working great so far.
Not exactly sure what this has to do with this issue but we were having the same problem. Testing in browser worked fine but the test kept failing. We ended up removing:
OmniAuth.config.test_mode = true
from the spec/support/omniauth_support.rb file and now our tests are passing.
Thanks for all of the awesome tutorials Ryan!!! I'm a total Rails/coding newbie and I managed to build a directory of printers for my IT dept with your help :). Now I followed this tutorial to try and get emails sent via a Gmail account to a list address (newprinter@domain.org) whenever a new printer is added to the directory. However, I'm stumped as to how to get this working with my rails app and I hope you or someone else can help. Please be gentle with me :). My app is a little different from your example code as I don't require a user registration, it's just a simple directory listing printers (make, model, IP address, IP address, etc.), and people can add/edit/delete printers from the "directory". I am including code from my app which I think is relevant below, although I could be wrong :). There's probably something horribly obvious to you or others which I am not seeing or able to figure out. I'd appreciate any help in advice on getting this working. Or if I should be going a different route to send the emails, please let me know.
This definitely clarified some questions I have about the differences between activemerchant, spree and some other systems. It seems that with active merchant you'll need to build out your order<->line item<-->products model. I think this is more suited for adding a /shop section on a blog or site that doesn't have ecommerce as a priority. Of course, this could be used to build fully fledge e-commerce solution, but why would one use this over spree?
I'm wondering if anyone has ideas on turning a custom page into a pdf. I have a search page. I have a custom action in my controller that looks like this..
So in fact it seems that i just learned something.
If i create an instance variable in my action
@last_posts = User.first.get_last_posts
but doesn't use this variable nowhere else in my action or view
then only the User.first call will be triggered to get the user so i can retrieve his last posts.
Then the user.get_last_posts call won't be triggered because the result of this request is never used in the rest off my app.
So, to be clear, when i define an instance variable, the object is keep in cache, and if it's needed later in the controller/view code, then the method associated i.e get_last _post is processed
am i right ?
Should i go see a railcast which perfectly explain this behavior ? :)
Hi i have a strange issue with fragment caching with rails 3.2 & memcached as a cache store.
I use framgent caching in a partial and loop on a instance variable @recent_posts in my index view.
The problem, i think, is in my index action.
I didn't change anything to my code, so normally,my partial should be cached but the sql request that get my @recent_post should be processed.
Or it appears that the first request trigger the sql but the requests after wont.
To be a little more precise, my @recent_posts is defined by something like that.
@recent_post = SomeModel.first.get_last_posts.
And it appear that the SomeModel.first call is triggered every time but only the .get_last_post sql request won't be processed for the 2+ request...
Great! :-)
Ryan, do you already use MiniTest instead of the "classic" stack around RSpec ect as your standard approach? Or does it depends and differ from project to project?
Are there still some gaps, some gems of the testing-ecosystem (like guard, spork, vcr, jasmine ect) that do not work yet properly with MiniTest?
Or, asked different: for someone who isn't yet a pro in rails-testing, should I invest time in RSpec ect. or MiniTest?
Thanks again for this cool episode!
So there is basically no need to setup all the extra classes, one can just use the rails internal stuff, including the test rake tasks...
@Ryan, is there a reason you created everything from scratch?
Or is it that when adding the minitest gem one has to do that to avoid using the ruby internal minitest?
one problem with using javascript tags is the 'j' escape function in rails doesn't work correctly or doesn't work how you might expect it to work. the string you send it is not always preserved and is corrupted in subtle ways.
for example if you have a string like:
"<foo>"
and if you have:
<%= javascript_tag do %>
window.myvar = '<%= j "<foo>" %>';
alert(window.myvar);
<% end %>
then window.myvar == "<foo>"
the j function really has to replace '<' and '>' with '\u003C' and '\u003E'.
@Jelkster Totally! I've been watching Railscasts since 2007 and I've learned so much from them. I'm happy to be giving back now. Keep up the awesome work, Ryan!
This is great! So I created a model and I am having a separate issue. Since I use the @errors = ActiveModel::Errors.new(self) collection in my initializer and validators, when I generate JSON to store in my NOSQL database, it's including all kinds of stuff that I don't want to store:
{"errors"=>#, @username="jasdeep", @validation_context=nil, @firstname="Jasdeep", @lastname="Jaitla", @messages={}>, "username"=>"jasdeep", "email"=>... and so on
I've tried calling:
@user.as_json(only: [ :username, :email, :firstname, :lastname ])
as recommended in: api.rubyonrails.org -- ActiveModel::Serializers::JSON
but it has no effect, it still outputs every attribute and object. I have looked EVERYWHERE googling for hours upon hours and still can't find a solution for this.
I've tried overriding as_json in my Model class, but still no effect.
Any help or pointers are appreciated...
class User
include ActiveModel::Validations
include ActiveModel::Conversion
include ActiveModel::Serialization
extend ActiveModel::Callbacks
extend ActiveModel::Naming
attr_accessor :username, :email, :password, ... etc
def as_json(options={})
super(:only => [:username, :email])
end
Thanks!
Rails/ActiveModel 3.2.1
Ruby 1.9.3.p0
Thanks for keeping on top of this Ryan. Railscasts is one of the few bills I smile when paying.
does this work for formtastic??? i can seem to make it work please help ..
Another awesome episode Ryan!
I'd also like to add my support for a follow up episode that covers cancellations, insufficient funds etc
Just want to add that it's watching episodes like this that shows what a fantastic Ruby coder you are Ryan! I always pick up some tip or another watching you code :)
"We use update_all here so that all of the updates are made in a single query"
hi Ryan, for me it still issues individual updates for each item in the list. that makes sense since the "update_all" call is inside of the each loop. am i missing something?
p.s. great work on the screencasts, keep 'em coming.
I'm using Stripe to put together a SaaS application. We create a customer (Stripe) and link it to the user (our app). We handle the upgrading, trials, and charging. Just charge expiring customers in our crontab.
Hi friends,
I am stuck with "undefined method `serialize_into_session'" caused by a call to sign_in_and_redirect. Any ideas?
Cheers.
I'm stack with this too. Any success?
solr (sunspot) supports synonyms. It should be easy to set up "mobile phones" and "nokia" as synonyms. I assume conditional logic like returning alcohol or whiskey if beer is not found is a lot more complex. Don't know if solr/lucene can do that out of box.
I've been using solr for a few weeks now and am pleasantly surprised how well it's coming together for our needs.
Excellent. Very clear. Does one really get a great performance gain by just using rack with a bunch of middleware for a simple app? Also, I'm thinking this is just instructive, as sinatra seems to cover most everything with minimal overhead already. Thanks again.
A note to anyone using this gem with seyhunak / twitter-bootstrap-rails gem.
if you use rails g bootstrap:layout to generate your application layout, you will need to go into the layout and take the javascript_include tag out of the very bottom of the layout and move it up to the top of it under the stylesheet_include tag or private_pub will not work!
Fought this issue for a couple hours.
+1. An episode on Grape would be awesome.
Just an fyi, using Rack 1.4.0 may cause the following error,
undefined method 'include?' for nil:NilClass
. Upgrading to 1.4.1 fixed the problem.ref: Link
Great episode still really useful
I'm currently in a position where my code is not on staging, but I'm using this service showoff.io to use the ipn simulator.
Perhaps someone else's in this same position this tool will make your localhost available on internet
Thanks
The mp4 and m4v videos for this episode don't seem to work on iOS 5.
Troy, yeah, it's just an updatable list of printers. Not doing it in Active Directory. Hopefully someone can help with my issues :)!
Hey 0ptimus - I'd REALLY like to see this app, I've been trying to get a similar type of app working..
Can you share some/all on github?
Feel free to email me - info on github..
--- EDIT ---
now that I'm re-reading this, maybe you didn't mean directory as "Active Directory"
I'm looking to integrate to AD to automatically notice new objects like printers and build a dashboard..
I used Valuable gem to implement something similar to activeattr with type and default. I'm using it with redis for persistence and it's working great so far.
Hi Ryan,
It looks like the caboo.se domain name has lapsed and has been taken over by a squatter.
Your pastie link to the original code will work if you update it to:
http://pastie.org/172566
Thanks so much for your screencasts. I refer back to them frequently.
I am having the same problem. Were you able to solve it?
There is a solution on how to resolve dependency.
So basically, you have to go to gemspec of metric_fu and change it from 0.3.0 to 0.6.4
Google it there is a better explanation of what I tried it roughly explain.
It is a great gem and hope you will enjoy reports provided by it.
Not exactly sure what this has to do with this issue but we were having the same problem. Testing in browser worked fine but the test kept failing. We ended up removing:
OmniAuth.config.test_mode = true
from the spec/support/omniauth_support.rb file and now our tests are passing.
Hope this helps :)
It's not Backbone submitting double parameters. It's rails duplicating the parameters so that you can do:
Entry.new(params)
or
Entry.new(params[:entry])
Thanks for all of the awesome tutorials Ryan!!! I'm a total Rails/coding newbie and I managed to build a directory of printers for my IT dept with your help :). Now I followed this tutorial to try and get emails sent via a Gmail account to a list address (newprinter@domain.org) whenever a new printer is added to the directory. However, I'm stumped as to how to get this working with my rails app and I hope you or someone else can help. Please be gentle with me :). My app is a little different from your example code as I don't require a user registration, it's just a simple directory listing printers (make, model, IP address, IP address, etc.), and people can add/edit/delete printers from the "directory". I am including code from my app which I think is relevant below, although I could be wrong :). There's probably something horribly obvious to you or others which I am not seeing or able to figure out. I'd appreciate any help in advice on getting this working. Or if I should be going a different route to send the emails, please let me know.
TIA,
Mark
Sample from my setup_mail.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => "587",
:domain => "mail.gmail.com",
:user_name => "myitdept@gmail.com",
:password => "secret",
:authentication => "plain",
:enable_starttls_auto => true
}
ActionMailer::Base.default_url_options[:host] = "localhost:80"
Mail.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
~
Sample from my notifier.rb
class Notifier < ActionMailer::Base
default :from => "myitdept@gmail.com"
def newprinter_notification(list)
@list = "newprinter@domain.org"
mail(:to => @list, :subject => "New Printer Added to Directory")
end
end
~
Sample from my printers_controller.rb
def create
@printer = Printer.new(params[:printer])
end
~
Hi Dave, curious if you found a solution for doing this with a many-many association.
Thanks in advance, Cole
This definitely clarified some questions I have about the differences between activemerchant, spree and some other systems. It seems that with active merchant you'll need to build out your order<->line item<-->products model. I think this is more suited for adding a /shop section on a blog or site that doesn't have ecommerce as a priority. Of course, this could be used to build fully fledge e-commerce solution, but why would one use this over spree?
I am getting this error as well, though without cancan. Same trace to rabl/template.rb:66...
Instead of
$(".pagination").html("Page is loading...");
use
$(this).parent().html("Page is loading...");
so it works when doing more than one pagination per page.
Can some one please teach me how to config and run Private_pub on Heroku? Thanks.
I'm wondering if anyone has ideas on turning a custom page into a pdf. I have a search page. I have a custom action in my controller that looks like this..
When I do this I get a "Completed 406 Not Acceptable". I've also tried to add a link_to to my view, and I get a different issue there. I've laid that out here. http://stackoverflow.com/questions/9381244/rails-3-passing-date-params-to-url Any help appreciated.
How I can Replace ActiveAdmin Default (login)Page Into my own Customize Login Page.Plz help?
Wouldn't that be a good way to call an external API?
So you could easily switch between a internal Database or external datastorage.
How do you call external APIs?
OMG. I was struggling this week with a database less model and here is a railscast on this! Thanks Ryan!
Finally, I tried out NoSQL.. thanks a lot Ryan.. I created a small blogpost myself to show how to use mongomapper in rails to use cloud database hosted by Mongolab..
and the answer
http://asciicasts.com/episodes/202-active-record-queries-in-rails-3
see lazy query
As far as SEO is concerned, is there a difference between mysite.com\records\1-my-record vs mysite.com\records\my-record ?
If the answer is no, this seems like a lot of work to remove a leading #?
So in fact it seems that i just learned something.
If i create an instance variable in my action
@last_posts = User.first.get_last_posts
but doesn't use this variable nowhere else in my action or view
then only the User.first call will be triggered to get the user so i can retrieve his last posts.
Then the user.get_last_posts call won't be triggered because the result of this request is never used in the rest off my app.
So, to be clear, when i define an instance variable, the object is keep in cache, and if it's needed later in the controller/view code, then the method associated i.e get_last _post is processed
am i right ?
Should i go see a railcast which perfectly explain this behavior ? :)
Hi i have a strange issue with fragment caching with rails 3.2 & memcached as a cache store.
I use framgent caching in a partial and loop on a instance variable @recent_posts in my index view.
The problem, i think, is in my index action.
I didn't change anything to my code, so normally,my partial should be cached but the sql request that get my @recent_post should be processed.
Or it appears that the first request trigger the sql but the requests after wont.
To be a little more precise, my @recent_posts is defined by something like that.
@recent_post = SomeModel.first.get_last_posts.
And it appear that the SomeModel.first call is triggered every time but only the .get_last_post sql request won't be processed for the 2+ request...
Any though ?
There appears to be a problem with pdfkit and the Rails 3.1+ asset pipeline. It still appears to be an open issue.
I ended up switching to wicked_pdf and it appears to handle stylesheets fine (but be aware that you need to use their stylesheet include tag).
that should be:
then
Great! :-)
Ryan, do you already use MiniTest instead of the "classic" stack around RSpec ect as your standard approach? Or does it depends and differ from project to project?
Are there still some gaps, some gems of the testing-ecosystem (like guard, spork, vcr, jasmine ect) that do not work yet properly with MiniTest?
Or, asked different: for someone who isn't yet a pro in rails-testing, should I invest time in RSpec ect. or MiniTest?
Thanks again for this cool episode!
Ah, okay, so I guess we can just wait for Rails 4 with fully integrated default minitest support and switch then ;-)
Because you won't be able to use minitest's advanced features if you stick with test/unit.
So there is basically no need to setup all the extra classes, one can just use the rails internal stuff, including the test rake tasks...
@Ryan, is there a reason you created everything from scratch?
Or is it that when adding the minitest gem one has to do that to avoid using the ruby internal minitest?
one problem with using javascript tags is the 'j' escape function in rails doesn't work correctly or doesn't work how you might expect it to work. the string you send it is not always preserved and is corrupted in subtle ways.
for example if you have a string like:
and if you have:
then window.myvar == "<foo>"
the j function really has to replace '<' and '>' with '\u003C' and '\u003E'.
Yep, ruby1.9 implements test/unit using minitest.
Hm, actually when I create a new rails app it uses minitest automatically with ruby 1.9.
At least I see the seed option in my test output...
It's small, fast and well designed. Ryan Davis gave an excellent talk on it, available here: http://confreaks.com/videos/618
That's awesome. You figure out a lot of things I'm just lazy to dig out. I'm sure this ep will encourage people to use MiniTest in their projects.