RailsCasts Pro episodes are now free!

Learn more or hide this

Greg Grillone's Profile

GitHub User: ggrillone

Site: gregorygrilone.org

Comments by Greg Grillone

Avatar

I am pretty new to json api's and have a beginner question. So in this video Ryan put's the json data in an html data attribute as opposed to using an ajax request to get the json data.

So let's say I have a respond_to block for html and json. When the page loads I make an ajax get request to load the data from the server. If I use a get request to retrieve the data, am I really making 2 calls to the database? The first triggered by the html format of the index action and the 2nd triggered by the get request?

Avatar

I'm getting this weird errror: "NameError (uninitialized constant ReportsController::ReportsDatatable):
app/controllers/reports_controller.rb:20:in `block (2 levels) in index'"

The weird thing is sometimes when I load the table I get this error, but other times I do not. Also everytime I try to go to the next page this error occurs.

Any ideas?

Avatar

One improvement I made was implementing an includes call and setting it to an instance variable so I can reuse the nested relationships without having to re-query the model every time:

def author_name
  posts_with_children.map do |post|
    post.comments.map do |comment|
      comment.author.name
    end
  end.join(',')
end

private
  def posts_with_children
    @children ||= posts(:include  => { :comments => { :include => :author } })
  end

This improved performance slightly, but not a significant amount. Right now I have an initial page load of 5 seconds, but that is only with 4k records. If anyone has any other advice on how to improve this further that would be great. Thanks.

Avatar

I am having some performance issues with deeply nested models. I have a parent Topic model. A topic has many posts, posts has many comments, and a comment has an author.

mapping do
  indexes :author_name, index: 'not_analyzed'
end

def author_name
  posts.map do |post|
    post.comments.map do |comment|
      comment.author.name
    end
  end.join(',')
end

Any tips on optimizing the performance?

Avatar

Awesome screencast! I've used this multiple times for reference and works great. However, I recently tried following this example, but instead of installing rbenv I had to use rvm. And when I get to the point of running 'cap deploy:cold' I keep getting the following error: sh: 1: bundle: not found. I installed bundler correctly and confirmed it by running 'bundle -v'. One thing I did notice in previous apps when following this tutorial (when using rbenv) that under my_app_directory/shared there would be a bundle/ directory, however now that directory doesn't exist, so maybe that is the 'bundle not found'? Any ideas?

Avatar

had the same issue and was stuck for hours. issue is with font awesome, here's the solution: https://github.com/seyhunak/twitter-bootstrap-rails/issues/292