Thanks for the info Ryan! I am glad that in later railscasts the example code is available for download. For those who are trying to get this to work today, you can download example code from my google code repo at:
A couple of differences:
-- changed the application concept a little to fit what I am trying to build. The structure is almost identical but I changed the names of the models.
-- replaced prototype with jQuery so the javascript is a little different from what you find in the cast.
-- this example code was build on rails 2.3.2.
I understand how to implement roles on the entire site, but how would you break this down even further, to an account level for example?
I have an application that hold accounts. Each account can have multiple users with multiple roles and each user could belong to multiple accounts, again, with differing roles. An editor of one account may be the owner of another, for example.
I'm struggling to see how I can check to see if the currently logged in user is in a particular role for the account that they are trying to access.
So far I have tried using a Privileges table that holds a user_id, role_id and account_id, but I can't find a way to find out if the current user within the current account belongs to a certain role.
Confused and probably making it worse for myself...
I have a question. I need to set up recurring job which can be send any minute of the day. I need to load rails environment every minute as cron job is running every minute. Which is the best way to do this ? Cron/Daemon or Starling ?
@Daan -- see if the code at http://gist.github.com/111459 works for you.
If not, install Firefox and the excellent Firebug add-on. Then enable the javascript console -- you can monitor what is sent, what is received, headers, everything. For even better deep inspection install the TamperData plugin -- you can pause and modify data as it enters and leaves the browser.
I had a bug with this approach on Internet Explorer. My remote form submissions were processed correctly on the server. However, rather than execute the returned callback script I was getting a "Security Error - File Download" and apprised that IE didn't know what to do with a 'text/javascript' file.
If you're fighting this, here's what I did.
In my case I've found out that IE doesn't set the accept headers correctly, so you SHOULD request a file with the right extension (.js, probably). In the railscast, Ryan, you allude to skipping this, and the change @Geoff (comment #16 above) mentions may be involved.
If you're not using one of the ruby remote form doodads, you'll want to not only set jQuery to munge the xhr headers, but also ensure the form is sent to /widget/69.js and not the default /widget/69
You can see the <a href="http://gist.github.com/111459">code snippet I use</a> at http://gist.github.com/111459
It's basically the same as in the railscast, but with the '+ ".js"' amendment in the jQuery.fn.submitWithAjax part
I also adorn the form's submit buttons with a spinner (using a CSS class), but that's just for shine.
As always, thanks a ton Ryan. Your episodes are monumentally helpful.
Hi Ryan. I am very new to Ruby on Rails. Advance search is what I was looking to implement. I did try it out but facing some problems. when i render the partial I get an error sayin template missing. I create the partial but what do i put in the show method??
Thanks for your railscast, Ryan! Nice compilation. I use mostly NewRelic for staging and production environments, and MySQL Query Reviewer for development mode:
I find this last one really helpful and unobstrusive. You just put it in your app, no config files, and it will show a tiny floating div you can unfold to get more details of the queries, with helpful tips to get a better performance on them. Only works with MySQL, though.
new_relic requires that you give them your email address and then they give you a config file. Otherwise you can't use it.
Tune-up on Ubuntu doesn't work well because it creates files that require root access. I've been unable to find the correct chmod to resolve this problem as it seems to create some files each time at start-up.
thanks for this, i was actually working on a app requiring this functionality not long ago but the whole authorisation thing with Restful_Authentication is so old; glad this gem freshens it up.
majorly glad all the core code doesn't go into my app, makes it a lot more cleaner.
The relic plugin isn't available at the momement
script/plugin install http://newrelic.rubyforge.org/svn/newrelic_rpm
.
.
.
+ ./lib/new_relic/config/ruby.rb
Plugin not found: ["http://newrelic.rubyforge.org/svn/newrelic_rpm"]
You may want to note that rack bug only works with Rails 2.3 or later. I tried on 2.1 and 2.2 and doesn't work because there is no ActionController::Dispatcher
Question for you. On the create action of the sessions controller, the password field you have on there, how are you going about that?
I am trying to use <% form_for ...
but can't think of an object to reference it to, since we have no User model in this scenario. Can you paste your create.erb and destroy.erb file code? That part just doesn't make sense to me...
Good news! Rails resources increasing! We got another site that posts podcast and video tutorials online! Just to let you all know this.. Please visit http://www.buildingwebapps.com/podcasts
We should really support these initiatives. Thanks Ryan and thanks Michael Slater/Christopher Haupt from LearningRails. You guys are doing a great job. Keep it up!
It seems that every time I have tried to integrate Five Runs into my application, I always get buggy results. This time I can view the drop down information, but there is now way for me to delve in deeper into the models and queries. I think the latest may only be useful for Rails 2.3.2 and not older. I'm running 2.2.2.
Great screencast though, Ryan! I wish I could have made it to Railsconf so I could have met you in person.
@Tim, I don't use any of these on a day-to-day basis, but I will boot one up occasionally when I need to figure out what Rails is doing.
Most often this is NewRelic's because it is most convenient if you are already using it for production too. But I am very intrigued by the other two, especially Rack::Bug which offers a boat-load of useful information and is extendable.
This looks really good.
I like to test first and add functionality as I go, just ended
up deleting and rewriting a lot of RA.
My only question is does it offer the same level of security as RA,
hashing strength etc?
Apologies for going off topic but how do you get the syntax highlighting on the page?
The plugin is really nice.But when I tried to show an image inside a table it shows both the image and the array object.Can you please help me in removing the array object and show only the image.
Here is my code
items= @products_site.select{|site| site.category_id == category}.map do |site|
I've followed this tutorial, but I have added another column to the comments model 'name', I'm not sure how to access this though in my view, as: article.comment.name, and variants of that give me the old undefined local variable or method error. Can anybody help?
Authlogic is awesome. Now if we could get a railscast that integrates authlogic with rails-authorization-plugin (http://github.com/DocSavage/rails-authorization-plugin/tree/master)... That would be fantastic!
@Chris: Sorry, for the delay in replying, only just remembered I posted this (as I moved on to working on a different problem!). I'll have a look at the Party super and subtypes; didn't think of that. :-)
Authlogic is working for me pretty good. However I am not able to get the documentation how to create a valid users.yml for functional testing. Any hints for me?
This plugin helped me a lot past few weeks when I by chance stumbled upon it as well. As I haven't been using RA due to the lack of customization this is really neat.
I stumbled across authlogic just a few days ago, then all of a sudden this pops up. Great screencast, can't wait to try it out for a project I'm starting!
Thanks for the info Ryan! I am glad that in later railscasts the example code is available for download. For those who are trying to get this to work today, you can download example code from my google code repo at:
https://gone-cat-open-source-software.googlecode.com/svn/tags/herbs-test-railscast-75
A couple of differences:
-- changed the application concept a little to fit what I am trying to build. The structure is almost identical but I changed the names of the models.
-- replaced prototype with jQuery so the javascript is a little different from what you find in the cast.
-- this example code was build on rails 2.3.2.
Hi.
I'm trying to test the renderer class but I can't figure out how what to send as "template" when I initiate an instance in my unit test.
For example one of my helpers has:
BoxesRenderer.new( @box, self )
with works perfectly.
But what to substitute "self" with in my unit tests?
Here is my code: http://pastie.org/478963
Hi
I understand how to implement roles on the entire site, but how would you break this down even further, to an account level for example?
I have an application that hold accounts. Each account can have multiple users with multiple roles and each user could belong to multiple accounts, again, with differing roles. An editor of one account may be the owner of another, for example.
I'm struggling to see how I can check to see if the currently logged in user is in a particular role for the account that they are trying to access.
So far I have tried using a Privileges table that holds a user_id, role_id and account_id, but I can't find a way to find out if the current user within the current account belongs to a certain role.
Confused and probably making it worse for myself...
Thanks for the great post.
I have a question. I need to set up recurring job which can be send any minute of the day. I need to load rails environment every minute as cron job is running every minute. Which is the best way to do this ? Cron/Daemon or Starling ?
@Daan -- see if the code at http://gist.github.com/111459 works for you.
If not, install Firefox and the excellent Firebug add-on. Then enable the javascript console -- you can monitor what is sent, what is received, headers, everything. For even better deep inspection install the TamperData plugin -- you can pause and modify data as it enters and leaves the browser.
I had a bug with this approach on Internet Explorer. My remote form submissions were processed correctly on the server. However, rather than execute the returned callback script I was getting a "Security Error - File Download" and apprised that IE didn't know what to do with a 'text/javascript' file.
If you're fighting this, here's what I did.
In my case I've found out that IE doesn't set the accept headers correctly, so you SHOULD request a file with the right extension (.js, probably). In the railscast, Ryan, you allude to skipping this, and the change @Geoff (comment #16 above) mentions may be involved.
If you're not using one of the ruby remote form doodads, you'll want to not only set jQuery to munge the xhr headers, but also ensure the form is sent to /widget/69.js and not the default /widget/69
You can see the <a href="http://gist.github.com/111459">code snippet I use</a> at http://gist.github.com/111459
It's basically the same as in the railscast, but with the '+ ".js"' amendment in the jQuery.fn.submitWithAjax part
I also adorn the form's submit buttons with a spinner (using a CSS class), but that's just for shine.
As always, thanks a ton Ryan. Your episodes are monumentally helpful.
Hi Ryan. I am very new to Ruby on Rails. Advance search is what I was looking to implement. I did try it out but facing some problems. when i render the partial I get an error sayin template missing. I create the partial but what do i put in the show method??
can you pls help
Thanks for your railscast, Ryan! Nice compilation. I use mostly NewRelic for staging and production environments, and MySQL Query Reviewer for development mode:
http://flouri.sh/2008/4/10/mysql-query-reviewer-now-with-ajax-and-profiling
I find this last one really helpful and unobstrusive. You just put it in your app, no config files, and it will show a tiny floating div you can unfold to get more details of the queries, with helpful tips to get a better performance on them. Only works with MySQL, though.
This guy documented all the steps without missing anything, use it it works:
http://snippets.aktagon.com/snippets/167-How-to-install-and-use-the-restful-authentication-Rails-plugin
new_relic requires that you give them your email address and then they give you a config file. Otherwise you can't use it.
Tune-up on Ubuntu doesn't work well because it creates files that require root access. I've been unable to find the correct chmod to resolve this problem as it seems to create some files each time at start-up.
Thank you Ryan for your great efforts ;-)
Hey Ryan, nice cast!
Got a off-topic question. What do you use to syntax-highlight your code snippets in the show notes?
I was looking around and couldn't find a good one.
Thanks!
thanks for this, i was actually working on a app requiring this functionality not long ago but the whole authorisation thing with Restful_Authentication is so old; glad this gem freshens it up.
majorly glad all the core code doesn't go into my app, makes it a lot more cleaner.
Appreciate it
And how can I profile actions which are called with Ajax?
Ryan, what color scheme do you use in textmate? I like the colors you have when editing are they preset ones or did you customize?
What is the best choice in production mode new_relic or 5runs?
Two ways to do :
1.find(:all).map{|t| t.name}
2.find(:all).collect(&:name)
The relic plugin isn't available at the momement
script/plugin install http://newrelic.rubyforge.org/svn/newrelic_rpm
.
.
.
+ ./lib/new_relic/config/ruby.rb
Plugin not found: ["http://newrelic.rubyforge.org/svn/newrelic_rpm"]
You may want to note that rack bug only works with Rails 2.3 or later. I tried on 2.1 and 2.2 and doesn't work because there is no ActionController::Dispatcher
Hey Ryan,
Question for you. On the create action of the sessions controller, the password field you have on there, how are you going about that?
I am trying to use <% form_for ...
but can't think of an object to reference it to, since we have no User model in this scenario. Can you paste your create.erb and destroy.erb file code? That part just doesn't make sense to me...
Very cool. Thanks a bunch Ryan!
Good news! Rails resources increasing! We got another site that posts podcast and video tutorials online! Just to let you all know this.. Please visit http://www.buildingwebapps.com/podcasts
We should really support these initiatives. Thanks Ryan and thanks Michael Slater/Christopher Haupt from LearningRails. You guys are doing a great job. Keep it up!
It seems that every time I have tried to integrate Five Runs into my application, I always get buggy results. This time I can view the drop down information, but there is now way for me to delve in deeper into the models and queries. I think the latest may only be useful for Rails 2.3.2 and not older. I'm running 2.2.2.
Great screencast though, Ryan! I wish I could have made it to Railsconf so I could have met you in person.
@Tim, I don't use any of these on a day-to-day basis, but I will boot one up occasionally when I need to figure out what Rails is doing.
Most often this is NewRelic's because it is most convenient if you are already using it for production too. But I am very intrigued by the other two, especially Rack::Bug which offers a boat-load of useful information and is extendable.
Ryan, I would love to hear which one of these tools you like the best, and which one you use (if any).
Comfirmed. You can use it as a gem in development too.
Yeahhh, monday! I so waited this moment. ;-) An another great and useful screencast, thank you! Ryan for the win! :-)
RPM is available as a gem as well, at least for production mode.
Thanks for the excellent cast.
The various search methods in the search model can be now replaced by named_scope definitions. Is it right?
Nadav
Always look forward to your screen cast every Monday morning! Keep it up!
I got stuck on this for ages.
There seems to be a bug where the validations ignore :if or :unless parameters.
Here is the reported bug and a patch.
https://thoughtbot.lighthouseapp.com/projects/8794/tickets/131-validates_attachment_presence-should_validate_attachment_presence-should-take-if-and-unless-options#ticket-131-1
Hi Ryan, thanks again for a great screencast. What do you prefer, webrat och cucumber for integration tests?
@Toggo: Have a look at the gist. http://gist.github.com/108808
This looks really good.
I like to test first and add functionality as I go, just ended
up deleting and rewriting a lot of RA.
My only question is does it offer the same level of security as RA,
hashing strength etc?
Apologies for going off topic but how do you get the syntax highlighting on the page?
Hello Ryan,
The plugin is really nice.But when I tried to show an image inside a table it shows both the image and the array object.Can you please help me in removing the array object and show only the image.
Here is my code
items= @products_site.select{|site| site.category_id == category}.map do |site|
[pdf.image("#{RAILS_ROOT}/public/images/message.jpg"),
site.product.barcode,
site.product.name,
number_to_currency(site.price)]
end
pdf.table items,:border_style=>:grid, :row_colors => ["FFFFFF","EFEFEF"],
:headers => ["IMAGE","ISBN", "TITLE", "PRICE"],
:align => { 0 => :center, 1 => :center, 2 => :center, 3 => :center,4=>:center,5=>:center },:border_width => 0.04,
:width=>500
end
I've followed this tutorial, but I have added another column to the comments model 'name', I'm not sure how to access this though in my view, as: article.comment.name, and variants of that give me the old undefined local variable or method error. Can anybody help?
isn`t it hard to add
format.html { redirect_to(posts_url) }
to your comment_controller?
i`m serfing without javascript
Yeah gotta thank you for this and nifty generators :)
Authlogic is awesome. Now if we could get a railscast that integrates authlogic with rails-authorization-plugin (http://github.com/DocSavage/rails-authorization-plugin/tree/master)... That would be fantastic!
I think that the use of "*files" in the helper method, looks like some kind of dereferenced pointer , but is a kind of understandig. God work - thx!
JOEY
@Tim thanks I figured that one out...
Any thoughts on why the code doesn't pass the purchase_options to paypal?
@Chris: Sorry, for the delay in replying, only just remembered I posted this (as I moved on to working on a different problem!). I'll have a look at the Party super and subtypes; didn't think of that. :-)
Authlogic is working for me pretty good. However I am not able to get the documentation how to create a valid users.yml for functional testing. Any hints for me?
Is it possible to use activeresource with MacRuby? I'm having troubles.
This plugin helped me a lot past few weeks when I by chance stumbled upon it as well. As I haven't been using RA due to the lack of customization this is really neat.
Thanks for the great Screencast.
My transactions suddenly seem to be going through to PayPal's development sandbox without any Billing information.
Do other gateways allow actual transactions without billing info (now possibly PayPal again)?
Clearly explains the usage of custom controller action along with :collection & :member routing resources.
Thank you Ryan
General tip: For the plugin installation command to work in the command line, be sure you've got git installed. Otherwise, the command fails silently.
I stumbled across authlogic just a few days ago, then all of a sudden this pops up. Great screencast, can't wait to try it out for a project I'm starting!
i get undefined method `title'. what is this 'title' anyway?