Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

kobaltz's Profile

GitHub User: kobaltz

Site: www.k-innovations.net

Comments by kobaltz

Avatar

For anyone wondering, this can now be accomplished by typing passenger start from the root of your application.

Avatar

Why couldn't you do

ruby
render "activities/#{activity.trackable_type.underscore}/#{activity.action}", activity.trackable_type.underscore.to_sym => activity

instead of creating the presenter. This seems much easier and less cluttered.

Avatar

Just for those who want their program to create the cron 0 9 1 * * which executes on the first day of each month at 9AM, you can do this.

ruby
every 1.month, :at => "start of the month at 9am" do
 #enter code
end

This is the same as :at => "9am" but is more humanized.

Avatar

Good screencast. However, one thing left out that was mentioned in the original ones is the :reject_if => :all_blank in the model.

Avatar

I am finding this to be the case as well. Have you found any work arounds?

Avatar

Has anyone tried creating the nested forms but allowing only a certain limit of answers or number of questions? Ideally, I would like the jQuery to disable the add link for new question or answer if the number of questions has reached the maximum for that user.

Avatar

If you are receiving an error message similar to

An unexpected error has occurred. We have been notified of the problem.

then this could be due to the fact that you have updated your API. I have a support ticket into Stripe to see what can be done about this. However, currently, I've just bypassed this error using the below coffeescript.

coffeescript --yum
      if response.error.message == "An unexpected error has occurred. We have been notified of the problem."
        $('input[type=submit]').attr('disabled', false)
      else
        $('#stripe_error').text(response.error.message)
        $('input[type=submit]').attr('disabled', false)
Avatar

I think that the thing that confuses me with all of these javascript frameworks is, why use Rails at this point? I understand the difference between client side and server side frameworks, but all of these seem to be really intrusive to the Rails framework. Instead of using the application controller and returning a JS on remote: true or having the coffeescript monitor a click, we have to go through this entirely different framework to accomplish a simple task. Does anyone else feel my pain?

Avatar

I take back what I said. It is more of a time saver than I had originally thought. I've posted the below generator.

https://github.com/kobaltz/app_template_generator

It creates
- Twitter Bootstrap
- Sorcery :remember_me and :reset_password
- CanCan 2.0
- Simple_Form

Ran a few successful tests. Definitely cuts out the BS in the setting up of base app and gets into the fun part. Almost reminds me of the yii demo app or asp.net mvc template app.

Huge time saver and less running around to find the old scripts for the authentication reset password stuff!

Avatar

In some cases, you can help the performance by pushing the assets to a different database. We have to keep detailed logs on a web application to track back changes made and can do this through having a beefier database server to handle the queries of the live logs.

ruby
log_database_producion:
  adapter: mysql
  host: other_host
  username: logmein
  password: supersecret
  database: logs

Then in your special model:

ruby
class AccessLog < ActiveRecord::Base
  establish_connection "log_database_#{Rails.env}"
end

To keep those pesky credentials from being in your application code.

If you want to reuse this connection in multiple models, you should create a new abstract class and inherit from it, because connections are tightly coupled to classes (as explained here, here, and here), and new connections will be created for each class.

If that is the case, set things up like so:

ruby
class LogDatabase < ActiveRecord::Base
  self.abstract_class = true
  establish_connection "log_database_#{Rails.env}"
end

class AccessLog < LogDatabase
end

class CheckoutLog < LogDatabase
end
Avatar

Good information, but most of these steps are almost hard coded into my brain already. However, I do see where it can be useful for creating templates for certain configurations with twitter-bootstrap, cancan, sorcery/devise, user model, etc. with the most commonly used gems.

Though, usually it only takes a few minutes to do this stuff now.

Didn't know about the appscrolls. Does seem useful.

Avatar

It would be neat if you showed how to make the slugs unique only to their parents and not site wide.

Avatar

Don't forget that if you are going to use something like this in a secure environment (SSL) then you should get a wildcard certificate. Otherwise your clients will get certificate errors.

Avatar

If you add this to the model, then these items will no longer appear on your dropdown list.

ruby
  UNRANSACKABLE_ATTRIBUTES = ["first_name", "updated_at"]

  def self.ransackable_attributes auth_object = nil
    (column_names - UNRANSACKABLE_ATTRIBUTES) + _ransackers.keys
  end

However, if you remove exclude an item using the list above, it will no longer become sortable.

Avatar

I agree. I plan to use this on my app. I'll probably check the size and if it's more than 5 items for that day will have a

<%= link_to "#{@model.size} more ...", list_of_models_path(@model) %>

Avatar

Has anyone else had issues and found a resolution when using Outlook or any kind of multipart/HTML email and have it format nicely. How did you handle email signatures with images?

Avatar

I've also used cancan to limit the user from voting on their own Answer/Question/Post.

Cancan and Reputation
      can [:new, :create], Answer
      can :manage, Answer, :user_id => user.id
      can :vote, Answer
      cannot :vote, Answer, :user_id => user.id
Avatar

I've taken the concept of if a user has voted for something and taken it a step further. The user can see if they have up voted something or down voted something.

ruby
        def up_voted_for?(item)
                  eval = evaluations.where(target_type: item.class, target_id: item.id).first
                  eval.present? && eval.value > 0 ? true : false
        end
ruby
        def down_voted_for?(item)
                  eval = evaluations.where(target_type: item.class, target_id: item.id).first
                  eval.present? && eval.value < 0 ? true : false
        end

This came in handy when I was checking to see if the user has up voted or not so I could change the image.

up voted
      <% if can? :vote, answers %>
        <% if current_user.up_voted_for?(answers) %>
          <%= image_tag("color_up_arrow.png") %>
        <% else %> 
          <%= link_to image_tag("gray_up_arrow.png"), vote_answer_path(answers, type: "up"), method: "post" %>
        <% end %>
      <% end %>
Avatar

I'm tending to agree after my initial relooks at Devise. I liked how Sorcery is very non invasive. However, it doesn't seem to be as fully functional out of the box. There's a bit more configuration work to be done with it (not always a bad thing).

Avatar

Sorry. Didn't fully understand your question. Answered prior to watching episode. ><

Avatar

I'm wondering if the encrypted password that Devise uses is more secure or equally as secure as the salted password that Sorcery users. The last thing that I would want to happen is to be a repeat of what LinkedIn recently faced. Any thoughts?

Avatar

In your model you can do something like this

validates_presence_of :password, :on => :create

Avatar

The only issue that I saw with the CSV export was that it would return all data from that table. I put it on a user list and has to make a index.csv.erb file that would post just the required data.

Not a big deal since I was able to put in whatever information I wanted.

ruby
First Name,Last Name,Email Address,Status,Company,Last Login,Last IP

<% @users.each do |user| %>

<%= user.first_name %>,<%= user.last_name %>,<%= user.email %>,<%= "Active" if user.user_status %><%= "Inactive" if not user.user_status %>,<%= user.company.company_name %>,<%= time_ago_in_words(user.updated_at.localtime) %>,<%= user.ipaddress %>

<% end %>
Avatar

Copycopter will be shutting down on April 15. It's a shame to see useful features die. I'm sure that they had good reasons, unlike they're like Google with Google Wave or Fox with any awesome show that died after 1/2 - 1 season.

Avatar

I found that in order for the card to process with your example, I had to put the variables in the card around { } and also delimit them with a comma.

ruby
  processCard: ->
    card =
      {number: $('#card_number').val(),
      cvc: $('#card_code').val(),
      expMonth: $('#card_month').val(),
      expYear: $('#card_year').val()}
    Stripe.createToken(card, subscription.handleStripeResponse)
Avatar

How did you get around the Twitter Bootstrap and Stripe issue?

I'm having issues in development mode where it's always returning an error with Invalid Token on the card. It's like it's trying to submit to Stripe with no card information.

ruby
{
  "plan": "2",
  "card": "",
  "description": "support@example.com"
}
Avatar

How would you handle having different configurations? Let's say a User logs into the system. Under their Account Settings, they can put in their pop/smtp settings and then use ActionMailer and MailMan with those settings vs having one configured for global use. One of the reasons why I ask is because the SendMail app within linux keeps getting flagged as spam and/or never reaches it's destination. However, this doesn't happen when using a SMTP server. I know that this is a bit off topic in general.

Avatar

How would you incorporate this with a many to many association where you have a product and category and an association model with product_id and category_id?

Avatar

You can also create a default one for any field. This will search for any value in any column.

Any Clause
when "allfields"
                                where('firstname LIKE ? OR lastname LIKE ? OR email LIKE ? OR manager LIKE ? OR address1 LIKE ?  OR address2 LIKE ?  OR city LIKE ?  OR state LIKE ?  OR zipcode LIKE ? ', "%#{search}%","%#{search}%", "%#{search}%","%#{search}%", "%#{search}%","%#{search}%", "%#{search}%","%#{search}%", "%#{search}%")                        
Avatar

Instead of just using name to search on, you can modify your model to include the field you wish to search on.

model
        def self.search(search,type)
          if search
            case type
                        when "firstname"
                                where('firstname LIKE ?', "%#{search}%")
                        when "lastname"                                
                                where('lastname LIKE ?', "%#{search}%")
                        when "email"
                                where('email LIKE ?', "%#{search}%")
                end
          else
            scoped
          end        
        end
Controller
USER.search(params[:search],params[:fieldtype])
index.html.erb
<%= select_tag "fieldtype", options_for_select([ "firstname", "lastname", "email" ], "firstname") %>
Avatar

instead of commenting out, try to remove the

#unless current_page.first?

#unless current_page.last?

Avatar

Looks like they have updated the :views file. If you're wanting to add the First/Previous/Next/Last in the view so that it doesn't disappear when appropriate, just remove the lines

unless current_page.first?

unless current_page.last?

in the _paginator.html.erb file