RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Charles is right! For more information, see the "Interaction States" section at http://docs.jquery.com/UI/Theming/API

If you want to read the jquery-ui code, you won't find the 'ui-state-*' classes in jquery.ui.autocomplete.js; you'll need to look in jquery.ui.menu.js.

Avatar

I am getting a ArgumentError wrong number of arguments (3 for 1), when I call the link_to_add_fields helper method. I've placed it outside of the block for fields_for, like so:

        <%= f.fields_for :exercise do |builder| %>
            <%= render 'exercise_fields', f: builder %>
        <% end %>
        <%= link_to_add_fields "Add Exercise", f, :exercises %>

I'm using rails 4.0 beta. Anyone have any idea why this could be happening?

Avatar

Another solution is GoGo, it creates a pseudo-shell with the Rails environment preloaded. https://github.com/brianhempel/gogo

Sounds similar to https://github.com/jugyo/rails-sh

Avatar

Hello

Need some help on this

I wiould like to do something like that :

ruby
 User.search({:profile_last_name_or_profile_first_name_cont_any=> 'jane doe'.split(' ')}).result

the SQL generated is the following

ruby
"SELECT \"users\".* FROM \"users\" LEFT OUTER JOIN \"profiles\" ON \"profiles\".\"user_id\" = \"users\".\"id\" WHERE (((\"profiles\".\"last_name\" ILIKE '%jane%' OR \"profiles\".\"last_name\" ILIKE '%doe%') OR (\"profiles\".\"first_name\" ILIKE '%jane%' OR \"profiles\".\"first_name\" ILIKE '%doe%')))"

which returns the expected results... But how to implement this request in my search form (in my view) and/or in my controller ?

My search form is :

ruby
<%= search_form_for @q, url: search_cockpit_users_path, method: 'post', id: 'users-search-form', class: 'span3 pull-right' do |su| %>
      <%= su.text_field :profile_last_name_or_profile_first_name_or_email_cont_any, :placeholder => 'full name or email contains' %>
      <%= su.submit 'Search', :name => nil, :class => 'btn ' %>
  <% end %>

As it is the SQL returned is

ruby
"SELECT \"users\".* FROM \"users\" LEFT OUTER JOIN \"profiles\" ON \"profiles\".\"user_id\" = \"users\".\"id\" WHERE (((\"profiles\".\"last_name\" ILIKE '%jane doe%') OR (\"profiles\".\"first_name\" ILIKE '%jane doe%')))"

but how to implement the split(' ') to have the expected SQL ?

Any help (and a bit of explanation) would be great, documentation is a bit light on the subject...
Cheers

Avatar

Using POW (and this example blog app) I got it working by setting Twitter callback url to....

http://blog-after.dev/auth/twitter/callback

Avatar

Hi everyone, I had a problem with my Nested Model From, I am not sure what did I do wrong,

My View projects/_form.html.erb
  <%= simple_form_for @project do |p| %>
          <%= p.input :name %>
          <%= p.input :description %>
    <%= p.simple_fields_for :tasks do |task| %>
      <%= task.input :description %>
    <% end %>
           <%= p.button :submit %>
  <% end %>
My Model - project.rb
  class Project < ActiveRecord::Base
   attr_accessible :description, :name, :tasks_attributes

   has_many :tasks
   accepts_nested_attributes_for :tasks, :reject_if => :all_blank, :allow_destroy => true
  end
My Model - description.rb
class Task < ActiveRecord::Base
  belongs_to :project
  attr_accessible :description, :done
end

When I try to render the from, the nested form field does not appear. Is there any problem with my codes ?

Avatar

No, cap deploy doesn't flush the db when you redeploy.

Suggest setting up a $5 per month instance on www.digitalocean.com and creating a test application so you can experiment.

Avatar

As of time of posting, 7th April 2012 ,tutorial still works fantastically on Ubuntu 12.10.

A few updates:

Delete the line in /etc/nginx/sites-enabled/default if you get the error bind() to [::]:80 failed (98: Address already in use)

listen [::]:80 default_server

If using 12.10 or 12.04 use

rbenv bootstrap-ubuntu-12-04

Postgres can still be installed using the method noted in the tutorial, but it's being depreciated in lieu of:

https://wiki.postgresql.org/wiki/Apt

Avatar

I am also trying to work out how to use hstore with a multi tenant app. Any help would be appreciated!

Avatar

In Rails 4 beta1, I'm getting a "HTTP/1.1 422 Unprocessable Entity" error when attempting a post request to an API. The controller is raising an ActionController::InvalidAuthenticityToken error.

Do I need to somehow disable request forgery protection for APIs?

Avatar

I'm having some trouble getting the sample to run. I downloaded the source and ran

bundle
rake db:migrate
rake db:seed
rails s

When I navigate to localhost:3000 in Chrome the list of names doesn't appear. What am I missing?

Avatar

Ryan,

Great screencast as always. Have you checked out https://github.com/nviennot/irb-config yet? It allows running tests from within the console as well, but it seems faster than the other tools.

Avatar

Commands works fine with Jruby, I use it.

Avatar

please provide solution as early as possible

ArgumentError in Active_admin/devise/sessions#new
Showing C:/Ruby193/lib/ruby/gems/1.9.1/gems/activeadmin-0.6.0/app/views/layouts/active_admin_logged_out.html.erb where line #9 raised:

different prefix: "C:/" and "G:/rails_workspace/newWorkspace/myActAdmin/app/assets/stylesheets"
(in G:/rails_workspace/newWorkspace/myActAdmin/app/assets/stylesheets/active_admin.css.scss)

Avatar

These tools have a few issues if you're using vagrant:

  1. They will try to create a socket file on your share, which doesn't support that file type. You can get around this in spring with the SPRING_TMP_PATH, but I don't think zeus has a configuration option for this.
  2. notification fs events don't work, so they need to fallback to fs polling instead.
Avatar

I tried to change DB from sqlite3 to mysql2, but I got the next error:

ActiveRecord::RecordNotFound in UsersController#new

Couldn't find User with id=1
Rails.root: /home/epuente/proyectos/ruby/auth

Application Trace | Framework Trace | Full Trace
app/controllers/application_controller.rb:7:in current_user'
app/views/layouts/application.html.erb:11:in
_app_views_layouts_application_html_erb__11355537_84799900'

Is there any idea how to solve this?

Avatar

Hi Ryan since you embedded faye gem, wouldn't be nice to embed this too? faye-rails

great gem by the way!
bye ;)

Avatar

Bitbucket hosts free private mercurial (hg) and git repositories and the capfile can just be changed to bitbuckets ssh link and it works like a charm. =)

Avatar

+1 for a redo of this episode showing API versioning and OAuth2. If you're focusing on providing an API, the view stuff is orthogonal.

Also, some context on perf would be very useful here.

Avatar

Anyone else having a problem when running cap deploy:setup and getting a chmod error :

failed: "sh -c 'chmod g+w /home/deployer/apps/blog /home/deployer/apps/blog/releases /home/deployer/apps/memDownDash/shared /home/deployer/apps/blog/shared/system /home/deployer/apps/blog/shared/log /home/deployer/apps/blog/shared/pids'" on 192.168.119.131

chmod:
"changing permissions of `/home/deployer/apps/blog/releases'
** [out :: 192.168.119.131] : Operation not permitted"

chmod:** [out :: 192.168.119.131] changing permissions of `/home/deployer/apps/blog'
** [out :: 192.168.119.131] : Operation not permitted

chmod:
** [out :: 192.168.119.131] changing permissions of `/home/deployer/apps/xxx/shared'
** [out :: 192.168.119.131] : Operation not permitted

chmod:
** [out :: 192.168.119.131] changing permissions of `/home/deployer/apps/blog/shared/system'
** [out :: 192.168.119.131] : Operation not permitted

chmod: changing permissions of `/home/deployer/apps/blog/shared/log': Operation not permitted

chmod: changing permissions of `/home/deployer/apps/blog/shared/pids': Operation not permitted

I setup a user in the admin group, and have "set :use_sudo, false"

Avatar

Are there any gem that speeds up rspec/capybara testing under Windows (besides Spork)?

Avatar

time rake db:migrate with normal macbook pro hdd: 2.x seconds
time rake db:migrate with samsung 840 pro ssd: 1.x seconds

I also feel the difference :)

Avatar

A little warning.

Have been playing around with rubber and using this great tutorial as a guide. Create 3 instances and forgot about them for some weeks... BANG, amazon send me a whopping bill of $168.

Play around with the t1.micro instance and not the instances that are being played around with in the rails cast!

Avatar

no evidence, but when I made the switch, I really felt the difference !

Avatar

If anyone gets an error about Undefined method `[]' for nil:NilClass this is because of this line: self.email = omniauth['user_info']['email'] if email.blank?

Due to some update this part should be changed 'user_info' to 'info', so self.email = omniauth['info']['email'] email.blank? or self.email = omniauth.info.email email.blank?

Avatar

Thanks for the explanation. I'm wondering though, how would you go about doing this if you're deploying to Heroku where it seems that you can't add or edit anything in the deployed application. I read that it's basically read only because any changes you make to any file are temporary and will be undone whenever you push your source code to Heroku.

Avatar

I couldn't get cropping to work with mini magick, but after trying some different things I still managed. Seems like someone has switched around on (X, Y) and (W, H).

This should work:

def crop
  manipulate! do |img|
    img.crop "#{model.width}x#{model.height}+#{model.x}+#{model.y}"
    img
  end
end
Avatar

For JRuby, you can use JRuby's bundled Nailgun server as an alternative to Spork. It'll be very familiar if you've ever run RSpec with a DRB server: http://blog.headius.com/2009/05/jruby-nailgun-support-in-130.html

Avatar

Great suggestion - did not know about this. You can also change the settings to use spring, by just prepending the rspec command with it...

Avatar

Thanks - good tips. So far I've been using "spin, combined with the kicker gem for autotests:
https://github.com/jstorimer/spin

Seems though Zeus and Spring are even easier to use.

Avatar

If you want to run tests from within Sublime Text, check out the RubyTest package. The README has instruction on configuring it for Zeus.

Avatar

Sadly, neither zeus or commands work under JRuby. This is because JRuby does not support Kernel#fork.

commands does work for running generate, and rake commands will also start quickly. rake 'test' also runs, but although it starts quickly, I believe it starts a separate process for the sub-tasks test:unit and test:functional.

Avatar

Hi

post published is very helpfull for me.Here you have carried out on single model.How to implement it for example like if User model has many association with Address model.I want user information in one form and Address information in Another form.Please explain me

Avatar

If you're a TMUX user I've found the Tmuxinator Gem to be fantastic way to setup and control multiple Rails dev environments.

Starting and/or attaching to an app's session is as simple as $ mux my_app; Adding Zues or Spring into the into Tmuxinator config is something I might try in order to further automate my dev environments.

If you frequently work on only 1 or 2 projects then you might not get a lot of milage out of TMUX. However, if you're like me -- I have 9 rails apps that I'm constantly switching between -- then it can make your life a lot easier.

Happy coding all :)

Avatar

Do you have some evidence for this?

Beyond the first run, the files should be paged into RAM anyway, so I would expect CPU to be the bottleneck, rather than disk.

(SSDs are great of course, I'm just not sure that it helps in this case).

Avatar

Hmm, I'm not able to find turbo patch for ruby 2.0, are you sure about that ?

Avatar

If you would like to use zeus, guard and parallel tests together check out https://github.com/sevos/zeus-parallel_tests

Avatar

With rvm, startups also much faster when optimization patches are used, for example ruby-1.9.3-p392-railsexpress or ruby-2.0.0-p0-turbo.

Avatar

One tip to fasten Rails' startup : buy a SSD drive ! It will make your life easier ;)

Avatar

Will this make tests in autotest or guard faster?