Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

Bharat Ruparel's Profile

GitHub User: bruparel

Comments by Bharat Ruparel

Avatar

Nice! Would like to see the Foundation's Javascript widgets compared to Bootstrap's.

Avatar

@laylester, could you please put out a sample/example on Github?
Thanks.
Bharat

Avatar

You do bring up a point. Understood and well taken. I cannot and will not speak for Ryan, so here is my take on it. The Pro episodes are by definition providing cutting edge research and we cannot expect him to express his opinion anymore than he already does while presenting the episodes.

What I find significantly more valuable is that more knowledgeable and experienced people with those technologies chime in and contribute their opinions and share their knowledge. Angular JS episode is a great example. I find Brandon Tilley's contributions so good that I am often referring to them as I am learning Angular JS.

This does not mean that I do not ask Ryan any questions or provide my feedback etc. I have found that he always responds to the feedback that I provide via emails and does not shy away from expressing his opinion. May be RailsCasts episode discussions are just not the right forum for him to take a position.

So, personally, it does not bother me that he chooses not to participate in the Railscasts forums anymore. What would bother me infinitely more is that he "stops" publishing the Railscasts. The research that he puts into them saves an incredible amount of time as a Rails developer.

Avatar

+1 for eager loading with polymorphic associations. A very common and real problem that should be addressed in a Pro episode. Thanks.

Avatar

Thanks for the fantastic research work Ryan. Now I know. Angular it is :)

Avatar

Thanks Brandon. This is an excellent explanation. Could you provide more details on how to "debug" an application that is using Angular.js? In the Backbone app., I just put a debugger statement where I need to and examine the code variables etc. in the debugger.

Can you elaborate on that a bit?

Bharat

Avatar

I think that you are getting stuck on the "literal" interpretation of a "single page" app. Instead think about the Rich client apps that we have been developing for the past 20 years using clients such as VB PowerBuilder etc. for client/server applications. A single page app is more akin to these Rich Client interfaces of the past years. It does not mean that "multiple" single page app(lets) cannot be bound together to create one "holistic" application. In fact, they have already implemented the Twitter Bootstrap UI widgets in Angular so it is a matter of stitching together many single page angular app(lets) using the UI elements such as tabs, forms, pop-ups, etc.

Avatar

You are so right! If you look at ATG Dynamo (acquired by Oracle), you will see a striking resemblance. It is a matter of personal preference really :)

Avatar

Hey Ryan,
You should continue with Angular JS screencasts to build a non-trivial application and then repeat the process with Ember JS. That will give us a good frame of reference. Your Backbone screencasts have been very useful to me in coming up to speed.
Just a suggestion.
Keep up the good work.

Avatar

Need help understanding Ryan's code for the services implementation!

I am reading Ryans code for Service Objects, specifically the PasswordReset class code. It has both the class methods and instance methods plus one instance variable @user which can be accessed via attr_reader class method, so far so good.

Consider the following class method in this service:

password_reset.rb
  def self.from_email(email)
    new User.find_by_email(email)
  end

It shows that the class method is returning a new instance of the "User" class, correct? See how he calls and uses it further in the PasswordResetsController class as shown below:

password_resets_controller.rb
  def create
    password_reset = PasswordReset.from_email(params[:email])
    if password_reset.user
      password_reset.send_email
      redirect_to root_url, notice: "Email sent with password reset instructions."
    else
      redirect_to new_password_reset_url, alert: "Email address does not match a user account."
    end
  end

it seems like his call to PassworReset's class method from_email is returning a new instance of the PasswordReset class itself. The method implementation shows that it is returning a new instance of the "User" class however. He then accesses the associated instance variable user via the newly created instance as shown in "if password_reset.user" line of the create method shown above. I am totally confused as to what is going on here. Is this an error? or some "quack quack" (duck typing mumbo jumbo) stuff going on here?

Kindly explain.

Thanks.

Bharat

Avatar

Grails which is inspired by Rails and written in Groovy, explicitly accounts for service objects just as Ryan explains here. I think for a few methods here and there, the "concern" or module mix-in approach is fine. But for something more substantial, a service object is better. It is a judgment call really.

Avatar

Ryan, Over the years, I have benefitted from your RailsCasts a lot. So I say this with nothing but sincere appreciation for what you have done and are doing for the Rails community. I totally second Sergey Kuleshov is saying above.

Please focus on specific topics that can be useful for a Rails developer and leave the innards of Rails to the Rails core team members and others who might be interested.

Avatar

It would be nice to have a part 3 or something which explains how this thought process carries over to CanCan, since you are the one who wrote it in the first place :)

Avatar

OK. I do not know much about the newer method. But the following works. It comes right out of Ryan's code on the RailsCasts itself which he has kindly open-sourced here:

https://github.com/ryanb/railscasts

In order to show a spinner on a page, you need to first create a div like so:

<div id="spinner" class="spinner">
<img id="img-spinner" src="/assets/spinner.gif" alt="Loading"/>
</div>"

Then in the document ready function, insert the following code:

$(document).ready(function(){
$("#spinner").bind("ajaxSend", function() {
$(this).show();
}).bind("ajaxStop", function() {
$(this).hide();
}).bind("ajaxError", function() {
$(this).hide();
});
});

The code is not mine, as I pointed out above, it comes from the RailsCasts code. I have tested it and it works as explained above. If this is not what you are looking for, please ignore.

Avatar

Perhaps because he wanted to demonstrate how simple it is to write "jQuery Plugins"?

Your solution is admittedly more mainstream, but is it more generic?

Avatar

Noel Rappin has a series of self published books on Javascript and he happens to use Rails as the server. They are fairly decent:

http://www.noelrappin.com/

Hope this helps

Avatar

Thanks. It works fine in Thin as suggested in the tread.

Avatar

I keep getting this message for every request to webrick:

Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2012-09-29 13:24:45 -0500
Served asset /jquery_ujs.js - 304 Not Modified (0ms)
[2012-09-29 13:24:45] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

Does not seem to do any harm. Would anyone know what is it and how to get rid of the warning?

Bharat

Avatar

Thanks for revising this. More episodes along these lines please.

Avatar

Morris.js looks super simple to setup and use.
My line charts required logarithmic Y-axis. So I had to settle on the Google Visualization API with the Visualr Gem. However, over time, I found it somewhat rigid. Therefore, I had to go to HighCharts which can do just about everything that I need to do. As Ryan points out, it is a commercial product though.

Avatar

I would also love to see Torquebox covered in an episode. I do have some experience with jRuby and concur with Martin. I would not use it for development purposes for the reasons that he mentions above.

jRuby is for deployment and integration with the Java world. It can be deployed on Tomcat which is the most widely used open source Java Server. As a matter of fact, Torquebox uses a customized Tomcat. Swing UI capabilities do seem promising though I have not written a Swing application in more than ten years, so I cannot comment on it.

All in all, a solid option for introducing Ruby in a Java entrenched enterprise.

Great work Ryan, appreciate the effort.

Avatar

Something is wrong with your configuration then. I downloaded the source and ran the "blog_after." It works perfectly.

Avatar

Many thanks. that did the trick. What an awesome tool!

Avatar

Meaning declaring the model attributes with attr_accessible? If that is what you are asking, yes I am.

Avatar

@Sam
This is very promising. I am following Ryan's screencast and everything works fine on my dev machine, but I do not see the Profiler Tab in my production environment on my local machine. Is there something different in your local gem?
Thanks.
Bharat

Avatar

Very nice! How about revising episode #8 "Layouts and Content For" episode?

Avatar

I have to agree with Andy. I have had to fight Devise a lot more than I would like to and therefore, I tried Sorcery for my current project. So far, it is working out great and it stays out of my way when I don't need it. Ryan has a screencast on it. Check it out.

Avatar

Hey Thanks Robert. Works like a charm from within the Rails Console. I could not make it work in the plain irb outside of Rails. May be I am missing something?

Avatar

Trying to adapt the open a specific method's source at a given line number which Ryan demonstrates using TextMate to VIM. Here is my code in the .irbrc file:

ruby
class Object                                                                                  
    def v(method_name)
      file, line = method(method_name).source_location
      `vi '#{file}' +#{line}`
    end
 end

Here is what I get when try to follow the number_to_currency example:

helper.v(:number_to_currency)
Vim: Warning: Output is not to a terminal

Any ideas anyone?

Thanks in advance.

Bharat

Avatar

A ton of useful information as usual :)
I use the ruby-debug gem and now debugger gem, which you recently covered in a revised episode. For a lone developer working by himself, being able to use the ruby-debug/debugger gem is an essential survival skill.
I was wondering if you use any techniques that are specifically applicable to debugging and finding what is not working faster? I haven't kept up with the Pry gem and tried to use it following your episode on it, but it was not a replacement for ruby-debug. Anything which helps find those pesky bugs faster would be super useful.

Avatar

Ya, A similar episode with Ember JS would be super useful. How does Node JS fit into all this?

Avatar

Does anyone know how to make Chosen behave with existing styles? It works in my simple_form based forms but it is completely out of whack with the styling of other elements? My form elements have the labels at the top with the input boxes/dropdowns in the bottom. Chosen forces the labels to be on left hand side. Also it is misaligned.

Any pointers on how to make it blend with the rest of the form?

Thanks.

Bharat

Avatar

Another excellent and very useful episode. Folks, there is a pattern here. When Ryan says, "Hold on to your seats." He is not kidding. That is when he is at his best :) Hey Ryan, please make a point of saying that every week in either the "Pro" or the "Revised" episodes :)
Best regards,
Bharat

Avatar
  1. ~/.profile file is quite safe.
  2. just remember to "export" to your environment like so: export GMAIL_USERNAME ='someone@gmail.com'

That should work. Works for me.

Avatar

Hey Ryan,
Fantastic coverage of Postgres. I switched to Postgres a year ago and that is my preferred database now. For the RailsCasts community, there are two more excellent references that you may want to look into:

  1. Peepcode screencast on Postgres: a bit dated but very very good.

https://peepcode.com/products/postgresql

  1. Tekpub's more recent screencasts, equally good

http://tekpub.com/productions/pg

As far as using Postgres with Rails, Railscasts videos are the best.

Bharat

Avatar

A note to the readers: If you try to run the sample app using the episode code from github, you will get an error when you click on the "product name" link. This is because the show view is referencing the category model but there is none in the current code base. So just delete the offending lines of code that references the @product.category.name field.

Avatar

May be you can open source some of your thoughts in a demo application? This way, we can all benefit from your knowledge. I do. Here is my open source File Manager app:

http://github.com/bruparel/file_manager

Avatar

you can run rake db:seeds as a remote task under Capistrano's control. See the revised screencast.

Avatar

I would check the following:
1. Make sure that your target server, e.g., Linode is known to your source, e.g., GitHub server.
2. Make sure that you can follow your script manually, i.e., type in each command on the terminal and see where you get asked a password related question and try to use public/private key authentication to automate the authentication process.
That should help you isolate the problem.

Avatar

I don't think you will pay much more than $40.00.
Though, as you see here, if you do this on Linode, the cost will easily be halved. This is a rough estimate based on my personal experience however and I may easily be off.

Avatar

This has got to be one of the most thoroughly researched and comprehensive Screencast produced by Ryan and he shines.

Nico Ritsche has a great point though. As one lone developer working on a big project (relatively speaking of course), I can simply rely on Heorku to do all my sys admin work and focus on the development. The Developer's docs are also of a high quality and very helpful.

Perhaps Ryan can do one screencast on Heroku?

Avatar

Great stuff Ryan. Nested forms revision will be great. Use your own Gem.

Avatar

It is not meant to be used for such forms (e.g. form_tag based forms which do not have an underlying model).
it is meant to be used for the forms which are connected to an underlying data table which happens to be majority of forms for a CRUD based Rails application.

Avatar

Hey Thanks Ryan,
Now the stage is all set for a set of Pro (Advanced) screencasts for leveraging SimpleForms with Twitter Bootstrap :)
Keep up the great work!

Avatar

I cannot post all my code here since even with simple_form, my form is quite large, but here is the gist:

ruby
= simple_form_for @contract do |f|
  %h3= "General Information"
  %table
    %tr
      %td
        = f.association :state, :collection => State.all, :include_blank => true
      %td
        = f.input :county_id do
          = f.grouped_collection_select :county_id, State.order(:name), :counties, :name, :id, :name, include_blank: true

Then you use the following coffeescript markup in app/assets/javascripts/contracts.js.coffee file:

javascript
jQuery ->
  counties = $('#contract_county_id').html()
  $('#contract_state_id').change ->
    state_id = $(this).val()
    state = $('#contract_state_id :selected').text()
    options = $(counties).filter("optgroup[label='#{state}']").html()
    if options
      $('#contract_county_id').html(options)
      $('#contract_county_id').parent().show()
    else
      $('#contract_county_id').empty()
      $('#contract_county_id').parent().hide()

So there is nothing that Simple form specific here really. It is the code from aforementioned revised screencast on dynamic menus tweaked for my own simple form.

Avatar

Hell Maxim,
You wrote:
"The latter of which I was hoping Ryan would cover, but topic is too wide, and this cast is great still"

I second that. Hey Ryan, there is room for Bootstrap Pro Advanced episode :)

Avatar

Very good. Would you care to share details? Avoid me the hassles. Thanks in advance.

Avatar

It is definitely a better strategy to use mixins as advocated in the article. This is a Twitter Basics screencasts so Ryan kept more advanced concepts out for simplicity.

Avatar

I think that the Less pre-compiler compiles it to CSS on the server and then ships it over the wire to the client?

Avatar

Hey Eric,
I thought Ryan mentioned that you have to define the variables up top before imports when you use SCSS as against Less? Is that the problem?
Just a guess.
Bharat

Avatar

Patrick,
Time to go "Pro". He covers this in the Pro episode :)

Avatar

Many Thanks Ryan. Please keep up the good work. May be you want to consider adding datatable jQuery plugin to further improve the user experience when working with Rails/Bootstrap? Here is the link:

http://datatables.net/blog/Twitter_Bootstrap

If not no worries though. I have already watched both the Bootstrap episodes twice and they are a hugh help for someone getting started with Bootstrap in the Rails environment.

Avatar

Hello Ryan,
If this is so simple now, is there a need to use gems like Devise and Sorcery anymore? What is it that you are doing in your consulting work? Please advise.
Thanks.
Bharat

Avatar

I second was Eric has said above.

We need deeper nuts and bolts level advice on integrating Rails with Coffeescript/backbones/Twitter Bootstrap/datatables (or a grid/table display widget) in a javascript (jQuery really) centric environment. There is a nice article published on Backbone/Twitter Bootstrap which Mike Gunderloy linked in his "A fresh cup" column today:

http://coenraets.org/blog/2012/02/sample-app-with-backbone-js-and-twitter-bootstrap/

If something like this can be done in a Rails environment, it gives us enough of a framework to create a nice look and feel.

Avatar

Way cool Ryan.
How about doing at least a two part series on Twitter Bootstrap? Simple form 2.0 has built-in support for it. It is great for people like me who are programmers but are design challenged :)

Avatar

This is fine actually. So you should not worry about it too much.

Avatar

Hello Ryan,
Murat has a good question above. I have the same question.
Can you please explain when and why would you choose this Gem over a CanCan driven soltuion?
Thanks.
Bharat

Avatar

Anyone running into CSV import issues, please modify the seed.rb file as follows:

require 'csv'

puts "Importing countries..."
CSV.foreach(Rails.root.join("countries.csv"), headers: true, encoding: "ISO8859-1") do |row|
Country.create! do |country|
country.id = row[0]
country.name = row[1]
end
end

puts "Importing states..."
CSV.foreach(Rails.root.join("states.csv"), headers: true, encoding: "ISO8859-1") do |row|
State.create! do |state|
state.name = row[0]
state.country_id = row[2]
end
end

Avatar

This is quite interesting. Can you do a similar screencast for handling incoming faxes and then routing them appropriately?
Thanks.
Bharat

Avatar

How about following up with a series of screen-casts using Simple Form gem? I have used it in the past and the current project and find it extremely useful. Moreover, the PlataformaTec crew manning the Google Group is super helpful. I think a set of "Professional Screencasts" on Simple forms where you go deeper into the subject matter just as you did with z-shell will be very useful.
This screencast was great. Keep up the good work.
Bharat

Avatar

Tying to pick up some Coffeescripting from this episode:

javascript
  processCard: ->
    card =
      number: $('#card_number').val()
      cvc: $('#card_code').val()
      expMonth: $('#card_month').val()
      expYear: $('#card_year').val()
    Stripe.createToken(card, subscription.handleStripeResponse)
  
  handleStripeResponse: (status, response) ->
    if status == 200
      $('#subscription_stripe_card_token').val(response.id)
      $('#new_subscription')[0].submit()
    else
      $('#stripe_error').text(response.error.message)
      $('input[type=submit]').attr('disabled', false)

Should the subscription.handleStripeResesponse function call not contain the two arguments (status and response) in the code above? The definition of the function includes these two.

Please explain.

Thanks.
Bharat

Avatar

Hello Helmut,
You may want to checkout http://www.peepcode.com. I subscribe to both (RailsCasts Pro and Peepcode) and find that they nicely compliment each other. Producing full length screencasts once a week is a very difficult thing to do. That is why Peepcode averages one screencasts a month (more or less). It is very nice to have Ryan's screencasts every week :)

Avatar

That is great news Ryan. Keep up the good work.
Best regards,
Bharat

Avatar

This is the best of both worlds. Free RailsCasts to get you going and Pro to push you further. I am waiting for your previous screen-casts to be brought up to date. There is a wealth of knowledge there already.

Keep them coming and congratulations on expanding on what you are already very good at. Can we expect you to respond more actively on the "Pro" screen-cast questions though? Since these are more in-depth, naturally there are more questions.
Bharat

Avatar

Hello Ken,
Haven't tried yet. Thanks for letting me know. I will install it now.

Avatar

Is anyone using Pry with Rails 3.1 RC5/RC6?
Thanks.
Bharat

Avatar

This is very useful. Can you please get into more details of the asset pipeline? You have a knack of getting to the point and getting it across.
Thanks.
Bharat

Avatar

Perhaps in an advanced sequel to this, you can cover one of the jQuery plug-ins to create a file manager style functionality. I have one open source implementation which is non-ajax here:
http://www.github.com/bruparel/file_manager
Thanks for this episode, I will be sure to look into this.

Avatar

Very useful. Keep them coming on Rails/jQuery theme now that 3.1 will ship with jQuery as the default.
Bharat

Avatar

Hello Ryan,
Please consider doing another episode using Devise's new omniauth integration support?
Thanks for all the hard work.
Bharat