Hi,
This video is excellent. However I have a dumb question (a bit new to rails world). I am building a social network site. So I have 2 users User-1 and User-2, Now how do I stop/restrict User-1 from editing or accessing a User-2 Profile (even though User-1 is signed_in). Can you please help me on this. I do not want User-1 to have access to User-2 account. I can put a dirty code to do the checks inside the controller, but would like to know if Devise has any such pre-built functionality to restrict (just like if signed_in?)
I think it's important to mention that when you set @current_user with cookie instead of session you lose the efficiency of rails CSRF protection.
It's happen because when rails protect_from_forgery method identify CSRF attack it's reset only the session and not the user's cookies.
To fix it you need to override handle_unverified_request()
at MODULE ActionController::RequestForgeryProtection::ClassMethods
and define it to delete auth_token cookie
I'm having an issue with testing this using Rspec and capybara. I can get and post in Rspec which will set and pass session variables, but when I try and do Capybara request specs I cannot. The end result is that I cannot test any page that has before_filter authorize set on its action.
Thanks for the plug, Linus! We're web developers at Websolr, and also felt the same pain of setting up and monitoring Solr servers for our client projects. Hence the birth of Websolr.
For those interested in trying out Websolr, you can use the coupon RAILSCAST278 at signup for your first month free of our Silver plan. (Or $25 off any other.)
Real-time indexing is available in recent versions of Lucene, and can be accessed in Solr if you are willing to roll up your sleeves and write some Java. We're beta testing our own flavor of it over at Websolr
Sphinx is faster for indexing, certainly, because Solr has a lot more overhead built in to that process. The 'client' software (Sunspot) has to fetch data from the database, format it into XML, then HTTP POST that XML back to Solr.
I like how Mat Brown (author of Sunspot) put it:
In my unbiased opinion, Solr is better than Sphinx in every way, except Sphinx is faster at reindexing the entire data set, which you pretty much never need to do. Unless you use Sphinx.
Regarding my above modifications, I needed "if password.present?" in the encrypt_password expression, otherwise it will end up encrypting an empty string when you save the user. You could also do this in a before_create callback or similar so it doesn't have to run on every single save.
Also, the find_by_email and authenticate methods need to be separated out. I changed it to:
...
user = User.find_by_email(params[:email])
if user && user.authenticate(params[:password])
...
Which I don't really like since I find relying on short circuit evaluation to be iffy.
Hi I'm relatively new to rails and havvn't used a plugin before so just a little lost at the beginning.
I'm using Ruby on Rails and can't follow where does the bash code goes.
Help please
I couldn't get the ".local" shortcut to work in Lion. After some searching online (here: http://www.justincarmony.com/blog/2011/07/27/mac-os-x-lion-etc-hosts-bugs-and-dns-resolution/), it looks like the ".local" TLD is reserved by Bonjour and so weird things happen with those domains. Instead, per the articles's suggestion, I used ".dev" instead and everything works great!
And now the main app uses haml for scaffold generation. That seems pretty counterintuitive, since it is within the class of the engine; think that's a bug I should file on Rails?
I was just playing around with this and noticed that the url helper prefixing seems to have changed. I am on Rails 3.1 rc5, but had to downgrade to Arel 2.1.4 to get things launched (which wouldn't seem to make a difference w/r/t this)
I believe Rails 3.2.0.beta fixes the bug where it creates both app/views/layouts/application.html.erb and app/views/layouts/uhoh/application.html.erb (where "uhoh" represents any mountable engine name).
How do I test mountable engine with RSpec? If I follow instructions from episode #275, generators use Test:Unit instead of RSpec, even though I have rails-rspec gem installed.
As usual, excellent screencast Ryan. Have you built tests for authentication with has_secure_password? I'm encountering this error when creating a user in a functional test:
ruby
NoMethodError: undefined method `password_digest' for #<User:0x007faf810f8b00>
From my experience, Sphinx is about 1000x faster than Solr when I have to index several millions rows from MySQL. And Sphinx can use case insensitive searching with different languages. I could not find Lucene collation files nor it was clear how to create them.
I advise to pay attention to ElasticSearch and Tire. He also ??based on Lucene, supports real time indexing and easy scalability. But if you don't need it, then better use the Sunspot :)
I am a newbie to Rails/web programming, and am following along with your railscasts, which have been an awesome resource. However, I have come across a problem I can't seem to fix here, despite following the railscast. I get this error when running the test:
Failure/Error: click_button "Reset Password"
AbstractController::ActionNotFound:
The action 'index' could not be found for PasswordResetsController
# (eval):2:in `click_button'
# ./spec/requests/password_resets_spec.rb:9:in `block (2 levels) in <top (required)>'
This, despite the fact that the create controller redirects to root_url, and when i do it through the browser, it works just fine. However, the test keeps wanting to route itself to the index action.
Don't use model.image.to_s but instead model.image.url
Using to_s breaks the default_url override if you want to use a default image when none exists.
This guy:
ruby
# Provide a default URL as a default if there hasn't been a file uploaded:defdefault_url"/images/fallback/" + [version_name, "default.png"].compact.join('_')
end
Hi Ryan, there is something wrong with this video. It stretched and cropped, so there is nothing to see.
Are you still using fixtures? It's interesting is there still need in using them or what are cases when you would need them? :) Thanks
Just been 2 weeks old with using thinking_sphinx AND Now This looks more doable already:(
I guess I'll stick with thinking the sphinx for now... untill next project
Thx a lot
Great, thanks for this!
Can you post your PasswordResetsController? It seems that it has no "index" action.
Maybe you misspelled it, happens to me all the time :-S
Hi,
This video is excellent. However I have a dumb question (a bit new to rails world). I am building a social network site. So I have 2 users User-1 and User-2, Now how do I stop/restrict User-1 from editing or accessing a User-2 Profile (even though User-1 is signed_in). Can you please help me on this. I do not want User-1 to have access to User-2 account. I can put a dirty code to do the checks inside the controller, but would like to know if Devise has any such pre-built functionality to restrict (just like if signed_in?)
Regards
Madhukar
I think it's important to mention that when you set @current_user with cookie instead of session you lose the efficiency of rails CSRF protection.
It's happen because when rails protect_from_forgery method identify CSRF attack it's reset only the session and not the user's cookies.
To fix it you need to override handle_unverified_request()
at MODULE ActionController::RequestForgeryProtection::ClassMethods
and define it to delete auth_token cookie
Hello
I'm having an issue with testing this using Rspec and capybara. I can get and post in Rspec which will set and pass session variables, but when I try and do Capybara request specs I cannot. The end result is that I cannot test any page that has before_filter authorize set on its action.
Thanks,
This is driving me crazy!
Thanks for the plug, Linus! We're web developers at Websolr, and also felt the same pain of setting up and monitoring Solr servers for our client projects. Hence the birth of Websolr.
For those interested in trying out Websolr, you can use the coupon
RAILSCAST278
at signup for your first month free of our Silver plan. (Or $25 off any other.)Real-time indexing is available in recent versions of Lucene, and can be accessed in Solr if you are willing to roll up your sleeves and write some Java. We're beta testing our own flavor of it over at Websolr
Sphinx is faster for indexing, certainly, because Solr has a lot more overhead built in to that process. The 'client' software (Sunspot) has to fetch data from the database, format it into XML, then HTTP POST that XML back to Solr.
I like how Mat Brown (author of Sunspot) put it:
There's some ongoing work to support the new, official Solr 3 spatial search APIs.
You're looking for the
highlight
method:Regarding my above modifications, I needed "if password.present?" in the encrypt_password expression, otherwise it will end up encrypting an empty string when you save the user. You could also do this in a before_create callback or similar so it doesn't have to run on every single save.
Also, the find_by_email and authenticate methods need to be separated out. I changed it to:
Which I don't really like since I find relying on short circuit evaluation to be iffy.
Hi I'm relatively new to rails and havvn't used a plugin before so just a little lost at the beginning.
I'm using Ruby on Rails and can't follow where does the bash code goes.
Help please
This tutorial is so freaking good. I think I just messed my pants a little.
I was wondering how sunspot compares with picky? http://florianhanke.com/picky/
It looks good, but it's not ready to use in nontrivial projects, you cannot use namescopes, something like this doesn't works
Product.published.near("Barcelona", 50, :order => :distance)
:(
By the way, will_paginate has now been updated for Rails 3!
https://github.com/mislav/will_paginate
No it's not a bug.
The only configs that are scoped to the engine are load_paths, eager_load_paths, and load_once_paths
I couldn't get the ".local" shortcut to work in Lion. After some searching online (here: http://www.justincarmony.com/blog/2011/07/27/mac-os-x-lion-etc-hosts-bugs-and-dns-resolution/), it looks like the ".local" TLD is reserved by Bonjour and so weird things happen with those domains. Instead, per the articles's suggestion, I used ".dev" instead and everything works great!
We're also have this problem when deploying with bundler. I found our problem on SO
http://stackoverflow.com/questions/6472785/bundler-error-on-deployment
Two of us worked on it for an hour and couldn't come up with any fixes.
I would like to see this Railscast updated for Rails 3.1...
It seems that configuration you place inside
lib/uhoh/engine.rb
will affect your main app's configuration attest/dummy/config/application.rb
I did this in my engine:
And now the main app uses haml for scaffold generation. That seems pretty counterintuitive, since it is within the class of the engine; think that's a bug I should file on Rails?
I was just playing around with this and noticed that the url helper prefixing seems to have changed. I am on Rails 3.1 rc5, but had to downgrade to Arel 2.1.4 to get things launched (which wouldn't seem to make a difference w/r/t this)
I believe Rails 3.2.0.beta fixes the bug where it creates both
app/views/layouts/application.html.erb
andapp/views/layouts/uhoh/application.html.erb
(where "uhoh" represents any mountable engine name).I keep getting
in my template I use:
in my application.rb it is defines
happens when a user is trying to reset the password.
For anyone interested in a much more advanced sunspot search, you can check out my demo here.
How do I test mountable engine with RSpec? If I follow instructions from episode #275, generators use Test:Unit instead of RSpec, even though I have rails-rspec gem installed.
Great tutorial/example, like so many before :)
Is there any way (like already available through Sunspot or other gem/plugin) to "colorize" the results?
Example:
i search for term "sunspot"
There is bunch of results (title, content...), but every word in the result list that contains "sunspot" is lets say green or something.
Thx!
Thanks for the great screencast.
A side note: I went through your github notes on how this website is configured and they were extremely useful to me.
I think it would be great to have a screencast showing how to configure a linode VPS for rails.
Really great screencast.
I had a question. Am I right in thinking that you use request specs in favor of controller specs? Or, do you write controller specs too?
I was wondering the same thing? I have thinking sphinx on my production server, but i think it takes a lot to always making sure its running...
Rails framework was structured perfectly. Why did they move js css under assets? What is the main reason?
Good screencast. Can you please explain why we need engine? Can I keep creating apps without engine or do I have to do it with?
Oh boy. I overlooked a failed migration and this was solved by simply fixing my test database structure.
As usual, excellent screencast Ryan. Have you built tests for authentication with has_secure_password? I'm encountering this error when creating a user in a functional test:
how can a solr search be combined with an activerecord find_by_sql call?
boosting a single attribute is simple
text :composition_name do
composition.name
end
```
You are right, it can be customized like this:
I think that the current Sunspot gem uses geohashing for spatial search which is inaccurate in certain scenarios.
Another well timed Railscast. Had to look at Solr today as the last thing to implement on a project.
Thanks very much!
Yes i'm facing problems with acts_as_tree while referencing another parent.
A has a child B then B becomes the child of C. It doesn't refresh the counter_cache for A and C, and i can't set it manually.
I had to force the update with :
Table.connection.update("UPDATE table SET children_count = #{old_parent['children_count'] -= 1} WHERE id = #{old_parent.id}")
If anyone knows any other solution i'm interested.
facebook won't be around in 10 years, i need my own login
From my experience, Sphinx is about 1000x faster than Solr when I have to index several millions rows from MySQL. And Sphinx can use case insensitive searching with different languages. I could not find Lucene collation files nor it was clear how to create them.
I used a Sunspot with Mongoid like:
gem 'sunspot_mongoid'
I advise to pay attention to ElasticSearch and Tire. He also ??based on Lucene, supports real time indexing and easy scalability. But if you don't need it, then better use the Sunspot :)
Hi,
I am a newbie to Rails/web programming, and am following along with your railscasts, which have been an awesome resource. However, I have come across a problem I can't seem to fix here, despite following the railscast. I get this error when running the test:
This, despite the fact that the create controller redirects to root_url, and when i do it through the browser, it works just fine. However, the test keeps wanting to route itself to the index action.
Anyone else get this error? Any ideas?
Don't use
model.image.to_s
but insteadmodel.image.url
Using to_s breaks the default_url override if you want to use a default image when none exists.
This guy:
Hi Ryan, there is something wrong with this video. It stretched and cropped, so there is nothing to see.
Are you still using fixtures? It's interesting is there still need in using them or what are cases when you would need them? :) Thanks
I would be interested to see the differences or advantages of Sunspot with Solr to Sphinx with Thinking Sphinx.
I haven't used Sunspot/Solr but from this video it seems to be quite similar in features & implementation with TS.
Just been 2 weeks old with using thinking_sphinx AND Now This looks more doable already:(
I guess I'll stick with thinking the sphinx for now... untill next project