RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Hey Guys i am a newbie to this...Based on this railcast i tried to do the following. Failed. Can anyone please help?

This is my View

`<%= f.association :product, :collection => Product.in_stock %>

<%= f.grouped_collection_select :batch_no, Product.in_stock, :store_opening_stocks, :title, :batch_no, :batch_no, :prompt => "Select Batch"%>`

This is Jquery.

jQuery(document).ready(function(){
var child = jQuery('.batch').html();
jQuery('.prod').change(function() {
var parent = jQuery('.prod :selected').text();
var escaped_parent = parent.replace(/([ #;&,.+*~\':"!^$[]()=>|\/@])/g, '\$1')

var options = jQuery(child).filter("optgroup[label='#{escaped_parent}']").html()
if (options) {
jQuery('.batch').html(options);
return jQuery('.batch').parent().show();
} else {
jQuery('.batch').empty();
}
});
});

Really need help been stuck for a week now. Any Help would be helpful.

Avatar

First of all: Great episode as always!

But I've got a question:
I tried to use the example from this episode with the creation of a new category in my app. I use internationalization there. Has anybody an idea how I could add the correct label to my text_field, without duplication inside my locales?

Avatar

It could be worth mentioning that if you are using the 1.4.1 version of omniauth-facebook gem, you could be running into this error:

OmniAuth::Strategies::OAuth2::CallbackError

By instead using the 1.4.0 version this problem was resolved, at least for me.

The issue causinh this problem is the one reported here

This does not prevent the error message in the JavaScript console, though.

Avatar

Btw I'm using rails 3.2.1 and ruby 1.9.3

Avatar

Has anyone faced this issue:

# example code
def member_logged_in(*args)
binding.pry
@member = Member.find(args[0])
@club = Club.find(@member.club_id])
mail(:to =>.....)
end

Under 'rails console', I can 'find' a member from the console prompt => @member.club_id returns a value.

When the same code is invoked via worker in Sidekiq, from the pry prompt, @member.club_id returns nil.

Thoughts?

Avatar

Sorry, my mistake. Actually request is aborted.

https://dl.dropbox.com/u/4109351/tmp/rack-mini-profiler-firebug-1.png

Should I post issue to community tracker?

Also thanks for awesome gem :D

Avatar

I updated from 0.11 to 0.14 BTW

Avatar

I'm running rack 1.2.5 and having a hard time upgrading it, seems like rails 3.0.14 and 3.0.15 depend on exact this version or at least bundler insists on it..

Thanks for your support.

Avatar

Hi every one.. if iam using mongoid(mongo database for creating user) with out having devise gem on it.. how can i find current user.

rails g model user provider uid name oauth_token oauth_expires_at:datetime
invoke mongoid
create app/models/user.rb
invoke test_unit
create test/unit/user_test.rb
create test/fixtures/users.yml

this is way i created user model, in model, i change the code like...

class User
include Mongoid::Document

def self.from_omniauth(auth)
auth.slice(:provider, :uid) do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name

user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!

end
end
end

in application.html.erb file how i need to get current user.. here we are using current_user right but if iam raise that, iam getting nill is current user.

Avatar

I'm using Ryan example tutorial file (example_before) which is provided by him. Version: rails 3.2.6 and Ruby 1.9.3.

Avatar

You are the bomb.
That solved my issues with Redcarpet.

Avatar

I have this working on 3.0.14 here, perhaps your version of rack is old, have you tried updating it?

Avatar

one thing that sticks out is that I did not do much 1.9.1 testing, also is there something about http authentication that you have configured in prd but not in dev?

Avatar

Again, nice tips Ryan.

I just prefer call async javascript througt a helper https://gist.github.com/3179378

Avatar

Hi @Sam - it works fine on my development machine but not on my production server, I get an 'Internal Server Error' and my production log shows:

Filter chain halted as #<Proc:0x000000059a2f68@/my_apps/apps/app_name/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_controller/metal/http_authentication.rb:112> rendered or redirected

Any ideas what's going on?

EDIT: I removed the http_basic_authenticate_with but it's still not working and there are no other clues in the log file :/

Avatar

"Ooh Dialup. That would be fun!"

Hahahahaha

Avatar

Interesting, what version of rails/ruby are you running, is there anything in the logs about the failure? Do you mind posting on http://community.miniprofiler.com

Avatar

I think the core of it was in maintaining the client side code, the server side was re-written pretty much with some similar paradigms

Avatar

can you post a screen shot at http://community.miniprofiler.com ideally with the type of failure (is it a 404 or 500, what is in the error?)

Avatar

interesting, @clay what version of the pg gem are your running? We are forced to monkey patch the async version of pg exec, perhaps we should fall back to the non async ones as well

Avatar

what version of rails/ruby are you running?

Avatar

what version of rails/ruby are you running?

Avatar

@dup2, have not tested 3.0.14, will test it out and reply on the community tracker.

Others, will try to respond to all the requests here today, but it would be mighty handy if you can post bugs/questions at http://community.miniprofiler.com

Avatar

Is anyone having a problem displaying the profile_image_url? My code is below. The only thing that will display is the alt text of the img, never the image itself. However, when I review HTML, it has a url in the img and if I hover over the link it displays the image itself. This tells me the path is correct.

Any suggestions would be greatly appreciated.

ruby
<% if Twitter.rate_limit_status.remaining_hits > 1 %>
  <% Twitter.search(Channel.find(params[:id]).channel_name, :lang => "en", :rpp => 4, :result_type => "recent").each do |tweet| %>
    <%=image_tag(tweet.profile_image_url, :size => "16x10") %>
    <blockqoute><%= tweet.text %></blockqoute>
    <hr>
  <% end %>
<% end %>
Avatar

A minor update is required for sunspot_rails 1.3.3 (rails 3.2.6)

$ rake sunspot:solr:start
  Note: This task has been moved to the sunspot_solr gem. To install, start and
  stop a local Solr instance, please add sunspot_solr to your Gemfile:

  group :development do
    gem 'sunspot_solr'
  end

The rake task remains the same after this change

Avatar

Try updating the pg gem. That did the trick for me.

Avatar

Hi everyone...

How can I change the required/not required property or a given field ... based on the value of another completely different field?

Avatar

Thanks for the introduction to MiniProfiler. I'm trying to use this on a 3.0.14 rails / 1.9.3-p194 ruby app without success.

NoMethodError: undefined method `bytesize' for #ActionDispatch::Response:0x000001035561b8

Could not find any documentation about minimal requirements. Anyone having the same issue?

Avatar

Some great tips again thanks Ryan.

If you want to check out more performance tips, see the work by Steve Souders http://stevesouders.com/

Avatar

You might be interested in this gem I made called CSV shaper that allows you to create CSV output using a really nice Ruby DSL.

https://github.com/paulspringett/csv_shaper

Avatar

Answering myself, there is an easy way, you just need to override confirmation_required? like this:

class User < ActiveRecord::Base
  def confirmation_required?
    super && email.present?
  end
end

Devise is great :)

Avatar

Thanks for another great episode, Ryan!

How would you do it if you also wanted to use the :confirmable module in Devise? This sends an email for confirmation on user creation, but it fails in the scenario where you don't require an email address.

Is there an easy way of not requiring email and only confirm it if provided?

Avatar

My unicorn workers die if I add rack-mini-profiler to my Gemfile. Ryan, do you know why this is happening?
At the moment I am profiling with thin, because I did not get it to run with Unicorn, but for better estimating performance problems, I would really like to profile with my production web server (unicorn)

Would be glad about any hints.

Anyway, great episode!

Avatar

Very nice Ryan! Thanks!

@Sam, as a suggestion, a post about the .net->ruby conversion would be awesome. And thanks for the great job!

Avatar

Thanks for tutorial, just installed gem and nothing happened. FireBug console shows that every request POST http://0.0.0.0:3000/mini-profiler-resources/results is failed without any additional information =/

Avatar

Hmm.. I installed the gem and the profiler tab shows up and displays the amount of time that loading took for a page, but it reports 0 sql queries for all pages. Any idea what's going on? I'm using postgres, but that shouldn't matter.

Avatar

Hi,ryan i couldn't create a SCAFFOLD...?
It throws error
`require': no such file to load --
json (LoadError)
Only when i include gem 'rack-mini-profiler' or else it's fine...
Help me to come out...

Avatar

Hi,

in my project I use meta_search to implement serching in my model

ruby
class Picture < ActiveRecord::Base
  include Rails.application.routes.url_helpers
  mount_uploader :avatar, AvatarUploader

  attr_accessor :prefix, :tag_list
  
  acts_as_ordered_taggable_on :tags

...

end

My controller is:

ruby
class PicturesController < ApplicationController

  def index
    if !params[:search].nil?
      @avatarSelected     ||= params[:search][:avatar_like].to_s
      @teggedSelected     ||= params[:search][:tagged_with_like].to_s
    end
    
    @search = Picture.search(:avatar_or_tag_taggings_tag_name_contains => params[:search])
    
    @search.meta_sort ||= 'created_at.desc'
    
    @pictures = @search.paginate(:page => params[:page], :per_page => 20)
    
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @pictures }
    end
  end

My _search.html.erb is:

ruby
                <%= form_for @search, :url => pictures_path, :html => {:method => :get} do |f| %>
                <table border="0" width="98%" align="center">
                        <tr>
                                <td>
                                    <%= f.label :avatar_like, "Filename" %>
                                    <%= f.text_field :avatar_like, :value => @avatarSelected %>
                          </td>
                    <td>
                                    <%= f.label :tagged_with_like, "Tegged wiith" %>
                                    <%= f.text_field :tagged_with_like, :value => @taggedSelected %>
                          </td>
                  </tr>        
                  <tr>
                                <td rowspan="2" align="center">
                                    <%= f.submit "Find" %>
                                  </td>
                        </tr>
                </table>
                <% end %>

I try the avatar_or_tag_taggings_tag_name_contains to combine a search on picture model witdh taggings, but widthout success.
Can you help me to do this?

Tank in advance
Steve

Avatar

Great Screen Cast Ryan

@pradeepbicc, Thats called as Nesting of routes.

Avatar

Thanks Ryan, for Great Tutorial.

I tried with your example_before application. But, it doesn't show the small Profiler box on left side.

I just added this gem 'rack-mini-profiler' on my Gemfile (example_before).

Is it enough?. Or need to make any additional configuration.

Avatar

This is a great little gem to see what overheads you are getting in your app due to not slim lining your SQL statements +1

Avatar

Thank you Ryan. The last two episodes are very handy and useful. Performance is a very important place in the expanding world of Internet.
+1

Avatar

I recently attended a conference in Australia and one of the talks covered off on the same sort of topic (link below). It was a little more in depth and focused on the inner workings of Chrome, but I thought it'd be worth sharing.

Thank you and great episode as always :)

http://lanyrd.com/2012/web-directions-code/swmwx/

Avatar

Big thanks Ryan, for the excellent Railscast!

Avatar

I would have liked to see how you handle concatenating multiple fields for the date/time/zone... rails date and time tag helpers are quite clumsy for users to operate. I tend to use text fields for both date and time and a select for time zone, with javascript popups for input selection. I hate the code in my model that puts this all together into a single database datetime column. Do you have a preferred method of handling this type of situation?

Avatar

Rayan,

Regarding to create a new comment on each model,

ruby
link_to "New Comment", [:new, @commentable, :comment]

I have "news" model and "task" model which is nested under "project" model routing

ruby
  resources :news
  resources :projects do
    resources :tasks do
      resources :comments
    end
  end

Is there a way to accomplish it so I don't have two links?

Avatar

I am having trouble getting the javascript to load properly

Uncaught TypeError: Object [object Object] has no method 'tokenInput'

any suggestions on what I'm missing and yes it is loaded in the list of scripts

Avatar

I found that nginx was using /var/run/nginx.pid instead of /tmp/nginx.pid for the pid file by default. Just had to change nginx.conf:

-pid /tmp/nginx.pid;
+pid /var/run/nginx.pid;