RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

+1 for same problem.
Not only when rails s running, but also any programs like vim. If I hit cmd + t when inside vim, the new tab is at home directory.

Avatar

Rick,

Sorry I have been away for a few days. I can display the table OK with pagination etc but still have the few issues mentioned above, including that I cannot sort or search the table. I intend to re-visit those problems later.

I have added some code to enable the user to select a row by clicking and render the appropriate view. The controller gets the correct id and the log shows the view as being rendered, but it does not show in the browser. I am working on that at present.

John

Avatar

Whenever I use the JS/Coffee code to log in using a pop-up I got:

ruby
(facebook) Authentication failure! invalid_credentials: OmniAuth::Strategies::OAuth2::CallbackError, OmniAuth::Strategies::OAuth2::CallbackError

Turns out this is due to a bug in omniauth-facebook 1.4.1 -- downgrading to 1.4.0 made it work.

Also, instead of hardcoding the path in the coffee file, I used:

ruby
window.location = '<%= Rails.application.routes.url_helpers.send(:user_omniauth_callback_path, :facebook) %>' if response.authResponse

Perhaps a little unwieldy - and I'd like to know a shorter way of doing this, but it works.

The above is akin to calling

ruby
user_omniauth_callback_path(:facebook)

In views etc.

PS ! Found out about the error from:
Link

Avatar

I know it has been several months, but I get the same msg but doesn't seem to hurt anything in production. I'd just like to stop if from annoying me every time I do a rails s or c. Any progress on the issue?

Avatar

Great episode! The only problem I have is dealing with many-to-many relations – sadly that doesn't seem to work so well with rails.

Avatar

hi,
thanks for the great cast.
I'm having this error:

undefined method `authenticates_with_sorcery!' for User:Class

this happens on my new app on rails 3.2.6 using the latest version of mongoid (episode #238)

looks like there was a known error with mongowrapper, maybe is this linked?
Any help would appreciated.
thanks

Avatar

Just a little update about using whenever with capistrano.
Now you don't need to create a task. You can just add this in your deploy.rb :
set :whenever_command, "bundle exec whenever"
set :whenever_environment, defer { stage }
require "whenever/capistrano"

If you look at the github of Whenever, it is explained.

Avatar

Hey, I keep getting these error on everything I try to do, products index, show and when I try to save a product. Any ideas ?

ruby
ActionView::Template::Error (undefined method `[]' for nil:NilClass):
    9:     <th></th>
    10:   </tr>
    11: 
    12: <% @products.each do |product| %>
    13:   <tr>
    14:     <td><%= product.name %></td>
    15:     <td><%= product.price %></td>
  app/views/products/index.html.erb:12:in `_app_views_products_index_html_erb___1596621271634774456_70157459562860'
  app/controllers/products_controller.rb:7:in `index'

nil:NilClass 
Avatar

I get the same thing. Followed the examples as well.

I'm on Debian Squeeze though.

Avatar

Thanks for the wonderful gem!

Ruby 1.9.2p290, Rails 3.2.7, Windows 7 here.

Shows load times but the SQL column is empty.

The dev database is on sqlite.

Avatar

Great Railscast! I've always used Heroku. Is there an equivalent command to 'heroku logs' on VPS with Nginx?

Thanks!

Avatar

Anybody has any tips on how to seed the database with the translations?

Avatar

Thank you Ryan. After struggling for a few days with Linode/Debian6/rvm/capistrano/passenger/enginx I gave up and followed this screencast to success in a couple of hours. I decided to follow exactly so my stack is the same as yours. I am sure I was doing terrible things with rvm. My brain isn't quite as large as Wayne's and rvm does a lot of magic with system commands such as cd. Even rvm implode didn't seem to uninstall without side effects. Hence the reinstall of the OS. I think rvm is powerful & useful and would love to see an in depth railscast on it.

Avatar

With activerecord-reputation-system 1.3.0,

You can use evaluated_by method to do this.

e.g.

ruby
Haiku.evaluated_by(:votes, @user)

will return all Haiku instances that are evaluated by @user.

Avatar

Can you post how you managed to do this on pastebin or upload source to github ? I want to able able to associate multiple accounts but am kinda lost.

Avatar

Good point (re: remember me from multiple machines).

Avatar

controller:

ruby
@media = @survey.build_media (if has_one association)

View:

erb
<%= fields_for :media do |f| %>
  <%= f.file_field :content %>   #@media.content is where the file goes
<% end %>
Avatar

I just came across this issue. It is as you expected: object.send(association) does not work the same way for has_one as it does for has_many. To get around this, I changed the link_to_add_fields helper as follows:

ruby
  def link_to_add_fields(name, f, association)
    new_object = f.object.class.reflect_on_association(association).klass.new
    id = new_object.object_id
    fields = f.fields_for(association, new_object, child_index: id) do |builder|
      render(association.to_s.pluralize + "/fields", f: builder)
    end
    link_to(name, '#', class: "add_fields", data: {id: id, fields: fields.gsub("\n", "")})
  end

Basically, I changed f.object.send(association).klass to f.object.class.reflect_on_association(association).klass and, since I use users/_fields.html.erb instead of user_fields.html.erb, I also changed the render line. Hope this helps, if you're still having that problem. If not, hope this helps some other lost soul of the future.

-Christian B.

Avatar

Getting 401 when clicking your twitter authentication link ?

You're probably developing on localhost!

What to do ? Edit the callback url in your twitter app.

Problem? Doesn't like localhost urls with ports in it (possibly disliking everything localhost in general).

What to do, then ? Encode your localhost url in a url shortener!

Example: http://localhost:3000/auth/twitter/callback
=> http://goo.gl/O5v3O

I used Google's URL shortener (@ http://goo.gl/ ) - simply set the address given by your URL-shortener of choice as the value of "Website: " under "Application Details".

Done and done.

PS!: Ryan didn't explicitly say this, but to use the ENV['TWITTER_SECRET'] etc you can set these values under environments/{development.rb,production.rb} like so:

ENV['TWITTER_SECRET'] = 'ssssh it is a SECRET!'

Avatar

John,

I would like to do a very similar thing with DataTables. Have you made any progress in how to display data from associated tables using server side processing?

--Rick

Avatar

This is great! But I am having a bit of an issue. I can not seem to get it to bypass the password as easily as it should be.

I am allowing login via facebook using the information from this railscasts. My resource is :subscriber instead of :user, but the rest is pretty much the same.

ruby
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
   def all
     subscriber = Subscriber.from_omniauth(request.env["omniauth.auth"])
     if subscriber.persisted?
       sign_in_and_redirect subscriber, notice: "Signed in!"
     else
        .....the rest of what you see in the railscasts

and my model contains:

ruby
   # populates db with information from omniauth'ed subscriber(facebook)                                         
   def self.from_omniauth(auth) 
     where(auth.slice(:provider, :uid)).first_or_create do |subscriber|                             
       subscriber.provider = auth.provider 
       subscriber.uid = auth.uid                                                                                 
       subscriber.email = auth.info.email 
       subscriber.firstname = auth.info.first_name                                            
       subscriber.lastname = auth.info.last_name 
     end 
   end   
         
   # persists subscriber information through the session 
   # when omniauth'ed subscriber (facebook)                                                                      
   def self.new_with_session(params, session) 
     if session["devise.subscriber_attributes"]                                                                  
       new(session["devise.subscriber_attributes"], without_protection: true) do |subscriber| 
         subscriber.attributes = params                                                   
         subscriber.valid? 
       end                                                                                     
     else 
       super                                                                                            
     end 
   end 
         
   def password_required?                                                                     
     super && provider.blank? 
   end 

When I run debugger and interject immediately before subscriber.persisted? I can see I have a provider and a uid for subscriber, but subscriber.persisted? returns false because subscriber.new_record? is true.

What am I missing?

Avatar

maybe a bit off subject but i am using omniauth to collect linked in profile data and am a bit stuck when it comes to getting info outside the - raise request.env["omniauth.auth"].to_yaml

I am trying to gain as much info as possible about signed in users such as past positions and location

here is the current user.rb save/create code

ruby
def self.from_omniauth(auth)
          where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
            user.provider = auth.provider
            user.uid = auth.uid
            user.name = auth.info.name
                  user.first_name = auth.info.first_name
                  user.last_name = auth.info.last_name
      user.image = auth.info.image
      user.industry = auth.info.industry
      user.current_job_title = auth.info.headline
      user.pub_profile = auth.info.urls.public_profile
      #user.interests = auth.info.interests
            user.save!
          end
        end

any help would be appreciated

Robbie

ps. i have had a look at this link but not sure how to go about getting the values into the db - [https://developer.linkedin.com/documents/profile-fields#profile]

Avatar

Looks like a great app!

I couldn't get it to work in my development environment, described in short the problem here:

http://community.miniprofiler.com/permalinks/85/rails-no-such-file-to-load----rack-mini-profiler-loaderror

Any hint?

Avatar

got it to work by downloading and manually installing the zip from github sunspot.

Avatar

hii everyone,

        I have integrate this tutorial with my ROR 
       application but i am facing a problem in logout 
       when i login with my facebook account to my 
       application its working but when i logout
      it only logout on my application not form facebook. 
      I have to logout manually on facebook.

       please help me out.            
Avatar

is password.present? necessary since validates_prescence_of :password, :on => :create already takes care of that?

Avatar

Another great screencast Ryan!

If anyone's looking for a good book to read on DBs, PragProg's 7 Databases in 7 Weeks is excellent. Which reminds me I need to finish it!

Avatar

I'm trying this line

ruby
pdf = OrderPdf.new(@order, view_context)

but I get this error "SyntaxError in xxxController#index"
syntax error, unexpected ',', expecting ')'

I get this error when adding the "view_context"

I'm using rails 3.2.5

Avatar

I was actually looking for a solution how to eagerly-load if the user voted on the answer, so that I can display a list of answers and tell if the user voted on them without doing the additional query.

I guess this could be done with some joins, but I wasn't able to do it with the activerecord-reputation-system.

Did anyone manage to do this?

Avatar

Won't this result in n+1 problems, where you're doing a query for each answer?

Avatar

Same here 0.11 to 0.14 fixed this...

Avatar

Unfortunately it seems to be impossible to set up Sunspot and Solr on Windows. Running rake sunspot:solr:run works fine, however, when trying to reindex or if on server development mode and perform the search method, you get the exception "No connection could be made because the target machine actively refused it. - connect(2)". I installed sunspot_rails and sunspot_solr today, so it should be the latest versions. Updated java as well today to 1.7.0_05. Now, here some people get it working by changing line 104 in server.rb from exec(Shellwords.shelljoin(command)) to system(Shellwords.shelljoin(command)), but this doesn't work for me either. I don't really see any possible solution left to try. Does anybody have an idea how to get it work on windows 7?

Avatar

Thanks for this! I was about to go search the Interwebz...Great screencast, Ryan!

Avatar

No one data store to rule them all. Different ones for different big data problems in the same application.

Avatar

Can you try using latest, I think I sorted this out

Avatar

All those who were having trouble, can you test again on 0.1.8, quite a few important fixes there

Avatar

+1 for coverage of the Rails OOP movement & how to achieve fast tests

Avatar

Hello! noob here, how do you add a "remove" item for this?? Thanks!

Avatar

Has anyone seen how to do associated_against with UUIDs? I am getting this error.

PG::Error: ERROR: operator does not exist: uuid = character varying
LINE 1: ...M "articles" INNER JOIN "forums" ON "forums"."id" = "article...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.

Avatar

Awesome Railscast!

Just wanted to mention that in the Mongo Shell you can use .pretty() at the end of your query, so you can get the pretty-printed output in mongo shell. This is similar to what you would get with "awesome_print" in irb or the rails console.

Avatar

I've got my app setup to have multiple organizations, and multiple pages per organization (identified via the subdomain). Is it possible to have FriendlyId check for uniqueness only on a per-user basis?

Thus that there can be multiple /home pages, but are unique within a given organization.

Avatar

They did wrong. That's true, MongoDB is not very good for abstracting complex social network structures. But MySQL is not any better either! For that class of problems the best solution is graph database. http://www.infoq.com/presentations/emil-eifrem-neo4j. (for Rails: http://neo4j.rubyforge.org/guides/rails3.html)