I am building and application which uses following railscast of Ryan
1. Authentication from scratch
2. Cancan for authorization
3. Multitenancy with scope.
4. Model name in url
It was working fine till the Multitenancy with scope but after implementing model-name in url i get following error in show action.
Couldn't find Article with id=batman-robin [WHERE "articles"."tenant_id" = 1]
If I comment out "load_and_authorize_resource" from controller the show action starts working. Can someone help me out with it?
Has anyone had any luck formatting simple_form with twitter bootstrap?
I'm unable to find a solution to getting the remember me checkbox and label to align correctly. I see online that its a bug but I don't see any type of solution.
I followed instructions to the letter and the request doesn't get routed to the handlebars file it gets routed to index.html.erb. Maybe I'm just tired but this is frustrating. Anyone know why it would route to the application/index file and not application.handlebars?
I have downloaded the source code for the custom s3_uploader_form which uploads straight to s3.
Straight out of the box I can't upload anything to S3 as it always renders an alert stating "upload failed" for everything, however there is nothing in the trace to suggest why. Removing the paintings.js.coffee code and adding a submit_tag to the form enables me to upload files to s3, however this doesn't create a rails object because the js handles that. (I have another app running with carrierwave so I know these credentials, secret, access key etc are all correct)
My question is why are no files being uploaded when paintings.js.coffee is handling the file upload process?
Very interesting episode, I'm just trying to implement this idea in my rails app to improve performance.
However Ryan's middleware fails if some of batch requests has status other than 200, e.g. 404:
ERROR NoMethodError: undefined method `join' for #<ActionDispatch::Response:0x378f9b20>
this error comes from last line of 'process_request' method.
I changed that line to:
First comment on railscasts, so here is the mandatory (and more than deserved) nicety : great job with this site!
Just a quick comment though that kept bugging me while watching this episode, since I'm a nitpicker. I don't like when the "else" is far from the "if", especially if the "if" is somewhat long. You could invert the condition here to make it easier to read. However, I also try to avoid 2-branches conditions when I can bail early. For example here, the first line could be "return @app.call(env) unless env["PATH_INFO"] == /batch", and you can then proceed with the rest of the function without the condition. General rule : when the first line of a method is an "if" and the last one closes that if you can always 1- avoid the 2 branches, 2 - both "branches" should be methods, if they are not simple one liners.
I guess there are many ways to refactor this, but that's the one I usually use :P To me it reads "proceed as normal, unless the path is /batch in which case, go on"
Sorry for the nitpicking on a very interesting episode
Any suggestions for how to implement caching of activerecord-reputation scores? Calculating these for each call creates a ton of overhead in my application.
Thank you for the screencast. I'm having an issue with the added condition fields disappearing after every post. My controller and routes code look exactly like Ryan's. I'm using the control-group and controls classes from Twitter bootstrap for form-horizontal layout. Is Ransack looking for fieldsets/fields classes by default?
If you are searching for a bootstrap theme that is both beautiful and Rails compatible, check out {rails}strap which I developed.
It includes many goodies and aims to be a business-oriented, clean and responsive design. Besides documentation it includes support, a plain HTML version and a example Application which shows you how to setup the layout.
Save some development time and make your Rails application stand out.
Love this episode. Very useful stuff Ryan. Great to see the mechanics of this explained. It would also be cool to wrap this up into a gem. Almost seems like something that should be added to Rails core!
Sorry. I found the problem, I just don't need to submit the form, because jquery file uploader does it automatically after selecting photos. Then, when I submit, no photos are being sent through the form, then create method is trying to save null.
I followed this video tutorial and every time I'm uploading photos, an additional line with NULL value to all columns is being created. So if I upload 3 photos are created four lines at database table, three OK and one null. Has anyone experienced the same problem or any idea where I could have been wrong? If I create a migration preventing null values in the column photo, an error occurs after upload:
Mysql2::Error: Column 'photo' cannot be null: INSERT INTO photos (created_at, project_id, photo, updated_at) VALUES ('2013-04-28 04:54:34', 19, NULL, '2013-04-28 04:54:34')
Followed the cast and for some reason when it exports CSV file, i get all records in one row and each cell is #User:0x007fb87415c460 and etc...any idea what could be causing this?
If you are searching for a bootstrap theme that is both beautiful and Rails compatible, check out {rails}strap which I developed.
It includes many goodies and aims to be a business-oriented, clean and responsive design. Besides documentation it includes support, a plain HTML version and a example Application which shows you how to setup the layout.
Save some development time and make your Rails application stand out.
I use RSpec to test this in a standalone engine. See https://github.com/lazylester/error_pages_engine. This way I can run the tests in a production environment just for testing the engine, and my application's test suite runs as usual in test environment.
Also since this functionality comprises a controller and views, is unrelated to the application's main functionality, and may be included in multiple apps, it seems to be a perfect place to use the Rails engine concept.
Hi Ryan,
Thanks for this. I was trying to write a custom rake task , say sending email And this has to be run against each tenant schema. I wrote lib/tasks/mailer.rake
desc "send mail for conditions"
task send_email: :environment do
#conditions
puts 'HHHHHHHHHHHHHHHHhh'
end
But this gives me error: undefined method `strip' for :"Run db:migrate for each tenant":Symbol
I have the lib/tasks/multitenant.rake like below
`db_tasks = %w[db:migrate db:migrate:up db:migrate:down db:rollback db:forward]
namespace :multitenant do
db_tasks.each do |task_name|
desc :"Run #{task_name} for each tenant"
task task_name => %w[environment db:load_config] do
Tenant.find_each do |tenant|
puts "Running #{task_name} for tenant#{tenant.id} (#{tenant.subdomain})"
tenant.scope_schema {Rake::Task[task_name].execute}
end
end
end
end
db_tasks.each do |task_name|
Rake::Task[task_name].enhance(["multitenant:#{task_name}"])`
I have the same problem of benniemietz, gon variables doesn't refresh after ajax call, I tried with gon.watch, reset and reload without success. Anybody has a suggestion?
I was incorrect :). page_path("about") always points me to /pages/about and page_path["about"] only works if I'm on the /about page manually, then it shows correctly. Otherwise it doesn't show the path. Shows the root path for some reason. Having fun looking at it though to figure it out.
I'd like to recommend Wiselinks:
https://github.com/igor-alexandrov/wiselinks
I like it better than both PJAX and Turbolinks
+1
Even without a large site, wiselinks is the way to go.
Did Ryan do a railscast on building this javascript task list? If so, which one was it? Many thanks.
Check the revision number for the DS.Store. It might need to be updated from 11 to 12
I am building and application which uses following railscast of Ryan
1. Authentication from scratch
2. Cancan for authorization
3. Multitenancy with scope.
4. Model name in url
It was working fine till the Multitenancy with scope but after implementing model-name in url i get following error in show action.
Couldn't find Article with id=batman-robin [WHERE "articles"."tenant_id" = 1]
If I comment out "load_and_authorize_resource" from controller the show action starts working. Can someone help me out with it?
Has anyone had any luck formatting simple_form with twitter bootstrap?
I'm unable to find a solution to getting the remember me checkbox and label to align correctly. I see online that its a bug but I don't see any type of solution.
I followed instructions to the letter and the request doesn't get routed to the handlebars file it gets routed to index.html.erb. Maybe I'm just tired but this is frustrating. Anyone know why it would route to the application/index file and not application.handlebars?
If I change the name of the record from A to B, I would like something like /products/A and products/B to work.
Is there an easy way to add this history functionality using this method, similar to what's included the Friendly_ID gem?
I have downloaded the source code for the custom s3_uploader_form which uploads straight to s3.
Straight out of the box I can't upload anything to S3 as it always renders an alert stating "upload failed" for everything, however there is nothing in the trace to suggest why. Removing the paintings.js.coffee code and adding a submit_tag to the form enables me to upload files to s3, however this doesn't create a rails object because the js handles that. (I have another app running with carrierwave so I know these credentials, secret, access key etc are all correct)
My question is why are no files being uploaded when paintings.js.coffee is handling the file upload process?
I have a stackoverflow question about this question as well. http://stackoverflow.com/questions/16291848/upload-straight-to-s3-failing-railscasts-pro-383
thanks again for a great episode Ryan!
@rbates Are you thinking to update this one ?
Very interesting episode, I'm just trying to implement this idea in my rails app to improve performance.
However Ryan's middleware fails if some of batch requests has status other than 200, e.g. 404:
this error comes from last line of 'process_request' method.
I changed that line to:
and it seems to work, but I'm not sure if this is bulletproof, so I will appreciate any thoughts on this
What would it look like to add two tags to an existing or new article at the rails command line?
Thanks!
+1!
First comment on railscasts, so here is the mandatory (and more than deserved) nicety : great job with this site!
Just a quick comment though that kept bugging me while watching this episode, since I'm a nitpicker. I don't like when the "else" is far from the "if", especially if the "if" is somewhat long. You could invert the condition here to make it easier to read. However, I also try to avoid 2-branches conditions when I can bail early. For example here, the first line could be "return @app.call(env) unless env["PATH_INFO"] == /batch", and you can then proceed with the rest of the function without the condition. General rule : when the first line of a method is an "if" and the last one closes that if you can always 1- avoid the 2 branches, 2 - both "branches" should be methods, if they are not simple one liners.
I guess there are many ways to refactor this, but that's the one I usually use :P To me it reads "proceed as normal, unless the path is /batch in which case, go on"
Sorry for the nitpicking on a very interesting episode
kind of answered my own question: this looks promising but have not validated it. http://jessewolgamott.com/blog/2012/01/19/the-one-with-a-json-api-login-using-devise/
I'm looking to do the same thing.. have you found any best practices for this?
Any suggestions for how to implement caching of activerecord-reputation scores? Calculating these for each call creates a ton of overhead in my application.
i have that problem and was going to other way for get the solution, thanks!
Ryan,
You already use something like that in production? How about performance, may need to limit requests or something like that right?
+1. Thanks.
Wow my test suite went from 1min30sec to 58 sec just by using the GC trick! Thank you!
Aye, me too. (Chrome on Mac Lion)
nice article
Same issue here
Issue solved
Got the same issue with the 5:13 -> 5:50...
I can't get the demo started. The console gives me this error Uncaught TypeError: Cannot call method 'match' of undefined.
I have created a stackoverflow thread as well to see if anyone else stumbled across this.
http://stackoverflow.com/questions/16267904/issue-getting-started-with-morris
Thank you for the screencast. I'm having an issue with the added condition fields disappearing after every post. My controller and routes code look exactly like Ryan's. I'm using the control-group and controls classes from Twitter bootstrap for form-horizontal layout. Is Ransack looking for fieldsets/fields classes by default?
Thanks for any help.
If you are searching for a bootstrap theme that is both beautiful and Rails compatible, check out {rails}strap which I developed.
It includes many goodies and aims to be a business-oriented, clean and responsive design. Besides documentation it includes support, a plain HTML version and a example Application which shows you how to setup the layout.
Save some development time and make your Rails application stand out.
Hi i try to use Devise but when register a new user in /user/sign_up he says
Unknown action
AbstractController::ActionNotFound
why? I followed the steps!
Anyone noticed strange artifacts between 5:13 and 5:50 mins when Ryan is explaining the Rack request variables (iTunes MP4 version)?
Love this episode. Very useful stuff Ryan. Great to see the mechanics of this explained. It would also be cool to wrap this up into a gem. Almost seems like something that should be added to Rails core!
Thanks! I would really like to see more episodes on the "offline" subject.
Sorry. I found the problem, I just don't need to submit the form, because jquery file uploader does it automatically after selecting photos. Then, when I submit, no photos are being sent through the form, then create method is trying to save null.
I followed this video tutorial and every time I'm uploading photos, an additional line with NULL value to all columns is being created. So if I upload 3 photos are created four lines at database table, three OK and one null. Has anyone experienced the same problem or any idea where I could have been wrong? If I create a migration preventing null values in the column photo, an error occurs after upload:
Also don't miss the excellent sessions from EmberCamp 2013
Check your initializer.
Not using this, but I believe paperclip supports S3 versioning
Displaying activity items generates a lot of sql queries, especially N+1 queries. Is there a way to get around this?
I'm getting the same thing.. not sure what the deal is! Unless it has something to do with me not using the "templates" folder?...
Followed the cast and for some reason when it exports CSV file, i get all records in one row and each cell is #User:0x007fb87415c460 and etc...any idea what could be causing this?
If you are searching for a bootstrap theme that is both beautiful and Rails compatible, check out {rails}strap which I developed.
It includes many goodies and aims to be a business-oriented, clean and responsive design. Besides documentation it includes support, a plain HTML version and a example Application which shows you how to setup the layout.
Save some development time and make your Rails application stand out.
I use RSpec to test this in a standalone engine. See https://github.com/lazylester/error_pages_engine. This way I can run the tests in a production environment just for testing the engine, and my application's test suite runs as usual in test environment.
Also since this functionality comprises a controller and views, is unrelated to the application's main functionality, and may be included in multiple apps, it seems to be a perfect place to use the Rails engine concept.
Hi Ryan,
Thanks for this. I was trying to write a custom rake task , say sending email And this has to be run against each tenant schema. I wrote lib/tasks/mailer.rake
desc "send mail for conditions"
task send_email: :environment do
#conditions
puts 'HHHHHHHHHHHHHHHHhh'
end
But this gives me error: undefined method `strip' for :"Run db:migrate for each tenant":Symbol
I have the lib/tasks/multitenant.rake like below
`db_tasks = %w[db:migrate db:migrate:up db:migrate:down db:rollback db:forward]
namespace :multitenant do
db_tasks.each do |task_name|
desc :"Run #{task_name} for each tenant"
task task_name => %w[environment db:load_config] do
Tenant.find_each do |tenant|
puts "Running #{task_name} for tenant#{tenant.id} (#{tenant.subdomain})"
tenant.scope_schema {Rake::Task[task_name].execute}
end
end
end
end
db_tasks.each do |task_name|
Rake::Task[task_name].enhance(["multitenant:#{task_name}"])`
Please help
Can any one suggest me for the edit action and the update action of this screencast strugling for the solution
I'm confused on what the benefit of using mustache over an js.erb. Is it better because the view is render almost completely on the client side?
In a model I only want to find those which didn't expire, yet.
For that I have a scope:
Should I use Time.current instead? I don't feel like I got the point :)
When I set this variable :ends_at, should I use Time.current + 30.days ?
Thx for the great work!
I have the same problem of benniemietz, gon variables doesn't refresh after ajax call, I tried with gon.watch, reset and reload without success. Anybody has a suggestion?
What a great episode! Thanks a lot for this, my test-suite is much faster now!
I was incorrect :). page_path("about") always points me to /pages/about and page_path["about"] only works if I'm on the /about page manually, then it shows correctly. Otherwise it doesn't show the path. Shows the root path for some reason. Having fun looking at it though to figure it out.