Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
True,

I'm getting this error: "undefined method `entries' for main:Object" line starting with "with_options" and the one right below it.

With this code:
code:
  map.resources :entries, :except => [:show],
      :member => {:promote => :get, :promote_top => :get, :demote => :get, :confirm_destroy => :get}, 
      :collection => {:admin => :get, :upcoming => :get},
      :shallow => true do |entry|
    entry.resources :comments, :member => {:confirm_destroy => :get}
  end
  with_options :controller => 'entries' do |entries_map|
    entries_map.entries '/', :action => 'index', :conditions => {:method => :get}
    entries_map.entries '/', :action => 'create', :conditions => {:method => :post}
  end

Adbot
ADBOT LOVES YOU

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Well I'll be, that works. Incredible that it does, confuses me a lot. Thanks.


Edit: also I was able to cram my map.root in there too.
code:
  map.with_options :controller => 'entries' do |entries_map|
    entries_map.entries '/', :action => 'index', :conditions => {:method => :get}
    entries_map.entries '/', :action => 'create', :conditions => {:method => :post}
    entries_map.root
  end

Nolgthorn fucked around with this message at 05:33 on Dec 23, 2008

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Fairly certain that attachment_fu still doesn't support cropping due to the vast differences between the many image processors out there. You may have a modified version of the plugin that is only designed to work with some processors and may be running on a different one by default in production.

Try this:
code:
class Photo < ActiveRecord::Base
	has_attachment 	:content_type => :image, 
                 	:storage => :file_system, 
                 	:max_size => 1.megabyte,
                 	:resize_to => '700x466>',
                 	:thumbnails => { 
                 		:thumb => '150x150>',
                 		:cropped => '70x70!',
                        :processor => :rmagick }
					
	validates_as_attachment
end
Merry Christmas!

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Pardot posted:

This is by far the best article on Rails 3 Merb/Rails merge, or Why should merbists be happy?, and it's answered all of the questions I had about what was in it for merb.

Why is it important to maintain any semblance of plugin backwards-compatibility? Generally if you're developing a Rails application, you use the latest version and go to production when it's done using whatever version you started with, unless there is a feature you absolutely need you wouldn't update it.

I would imagine there is a lot of code that could be different or that is different in Merb, why keep all these old methods? Isn't that all the opposite of trimming down the bloat Rails has been accumulating and the opposite of making it run faster?

Edit: Ohhh they're just talking about a public API for plugin functionality... ok I guess.

I really hope they bring Merb's slices.

Nolgthorn fucked around with this message at 11:29 on Dec 26, 2008

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I still think you would benefit by specifying the image processor you want if you're going to be using cropping.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Is there a way to easily report at the bottom of the page on a development application the processing time, requests and speed of which the page loaded? I am getting tired of always looking over to my terminal window on every page request to see even just a summary of what's been happening.

Also another question; I understand that the development environment runs a bit differently than in production. Now that I've got my db requests more or less optimized for the time being I'm noticing that my bottleneck seems to be loading partials, for instance I am using a commenting system and each comment is a partial with another partial in it for the rating system. When there are 25 comments being loaded on the page each one loads at a speed of between 0.7-1.7ms for the rating and 1-3ms per comment, in comparison the full amount of db requests on such a complex page load maybe 0.3ms in absolute total.

Why are the partials being loaded slowly, in production are these partials just going to be in memory or something?

Thanks in advance for both questions

Nolgthorn fucked around with this message at 01:50 on Dec 29, 2008

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Thanks you guys for your help.

I have another question that might be really simple.

Is there a way I can update a column in the database on a table that contains a field named updated_on, without having the updated_on field update?

In the old days it was possible to do:
code:
update_attribute('column', value)
This was special because it didn't fire off validations or do anything except update the column, but it seems that in the latest Rails it does do all those other things; can I get that old functionality back or what is the workaround for it?


Edit: It seems that I cannot even hack my way around it, here is my fat controller code:
code:
  def update
    verify_is_owner(@forum_thread)
    old_updated_on = @forum_thread.updated_on                       #<= Look here
    @forum_thread.attributes = params[:forum_thread]
    @first_post = @forum_thread.first_post
    @first_post.attributes = params[:first_post]
    if @first_post.valid? and @forum_thread.save
      @first_post.save
      @forum_thread.update_preview(@first_post)
      @forum_thread.update_attribute('updated_on', old_updated_on)  #<= Look here
      flash[:notice] = "Changes saved"
      redirect_to thread_path(@forum_thread)
    else
      render :action => :edit
    end
  end
It seems using update_attribute to change the 'updated_on' column will cause Rails to update the 'updated_on' column to the current time.


I may need to call the column something different if I want to have more control over it I guess.

Nolgthorn fucked around with this message at 12:05 on Dec 29, 2008

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I am being honest when I say that is some of the ugliest code I have written... sigh the Internet and posting things I will regret.

The code would look a lot cleaner if 'they' at Rails core would get associated objects built all in one request, that way I could easily tuck the params[:first_post] inside of params[:forum_thread][:comment] and be done with the whole thing. I did try putting some logic in my model for this along the lines of:
code:
  def comment=(comment_attributes)
    first_post = comments.find(:first, :order => "comments.created_at")
    if first_post
      first_post.attributes = comment_attributes
    else
      comments.new(comment_attributes)
    end
  end
But I don't remember now what was going wrong with the code that I gave it up.

I have since renamed the offending column like you guys have mentioned, I don't fully know what I was thinking... something seems simple and I get further along then it's no longer any good for my purposes. I am however going to maintain that && is more or less exactly the same as 'and' for me generally because I only ever use 'if' or 'unless' statements with booleans.

Nolgthorn fucked around with this message at 17:32 on Dec 29, 2008

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Exactly, except that it would do something once it hit the .new(params) method.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I too don't like the way field_error_proc adds that horrible div around failing form elements, it's always messing up my layouts.

I usually make it a point to add this at the very end of my environment.rb:
code:
ActionView::Base.field_error_proc = Proc.new {|html_tag, instance| "<span class=\"field_with_errors\">#{html_tag}</span>"}
But you could probably change it to suit your needs.

Edit: As a related question is there a way to reliably return error messages on the fields from an associated model, then display them or what is the best practice for this?

Nolgthorn fucked around with this message at 15:20 on Dec 31, 2008

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Usually I use paragraph tags around my form elements, then I have things on the right of it or maybe I've got a field in the middle of a sentence for some reason I dunno stuff gets messed up. True I could use display inline on the divs but why not use span though, it's nice to have the control.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Panic! at the Fist Jab posted:

Is anyone using edge Rails and the latest featureset that Rails provides consistently? I stopped using Rails about a year ago and focused on microframeworks like Sinatra, and I'm wondering if there's anything really amazing that I'm missing that the switch to Rails may be worth it again. Any awesome plugins, etc...

No not really, I am really looking forward to Rails 3 they promise to merge Merb and hopefully we get nice little things like recursive database manipulation.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Sewer Adventure posted:

How can I expire a cache from a model? expire_fragment only works in controllers.

The best idea is to use sweepers and set them up to expire the cache when the model performs certain actions.


At least that's what everyone will tell you in order not to break MVC. Alternatively you can just explicitly call the method you need using something like this:
code:
ActionController::Base.expire_fragment
Except whatever the correct one is instead.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I've been playing around with Authlogic for my new application.

It seems to me it is very nice.

For some reason it doesn't have a great grasp of telling me what is best for my database while using it. For instance, the suggestion on the site offers migrations which include :null => false on just about every single field and things like :default => "" etc, but not in all examples. Why are things like this so prevalent in so many gems and plugin tutorials out there? Personally I prefer to handle all of that "is-it-blank?" validation stuff in the model, if it gets by the model I probably planned on it going into the database not being rejected for some reason after it gets there or being replaced with "" instead of being null.

The other thing it seems to not be mentioning is to add indexes to any of the database fields, is this common practice too? I would think for logging in purposes things like the login field should be indexed.

What about all of those <blank>_token fields? Those should be indexed too...

I'm always so confused when I hit the migrations portion of any tutorial because they still seem to not do things the way I do them. Is there a benefit to not indexing fields and is there a benefit to adding restrictions or defaults to the fields in a clean database?


Edit: Besides setting a boolean field to default false or a <blank>_count field to 0...
:shobon:

Also doesn't setting a default on a field in migrations negate the :null => false assignment anyway?

Nolgthorn fucked around with this message at 07:29 on Feb 16, 2009

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Trabisnikof posted:

In other news Passenger is awesome, but first load is slow. Sports at 11.

It still doesn't get us past using god drat horrible awful terrible capistrano though, which is my biggest grief, so it's useless to me until that day which I'm dreaming of.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I've always felt after being tutored on and using capistrano that it is far too complex for something as simple as a rails deployment. I can perform deployments faster with less issues just using a SFTP client of my choosing.

Really, capistrano is unnecessary all you need is to move the files onto the server, perform some rights management on the files create a symlink and that's it.

This could all probably be done extremely easily with a bash script. Instead capistrano comes lumbering in with it's billions of lines of code and complete absurdity to "do it for me" which is crap too since I have to go out of my way to tell it not to do things that break the deployment if left alone.

I don't even fully grasp the benefit of a server side huge ton bunch of file changes and history of the application, but even that is handled by svn not capistrano.

Capistrano is a big piece of crap. <:mad:>

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

savetheclocktower posted:

Ah, how sloppy of me. I think I was thinking of Markaby.
Ohh neat!


There does seem to be a trend towards Ruby but Ruby is a really really good high level programming language.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Drogadon posted:

This week I got introduced to the wonders of HAML/SASS and was further blown away by Compass using the Blueprint CSS framework.


Awesome :D

http://haml.hamptoncatlin.com/
http://acts-as-architect.blogspot.com/2008/11/compass-primer.html

I've just been working with this today! A few notes:

Here is the guide I used to get up and running with compass and blueprintcss on Rails:
http://github.com/chriseppstein/compass-rails-sample-application/blob/81ab7a654754e30f76560018c58b90d05e8200dd/README

After that I wanted to vendor the gem, so I added these two lines to my environment.rb:
code:
Rails::Initializer.run do |config|
  config.gem "haml"
  config.gem "chriseppstein-compass", :lib => "compass", :source => "http://gems.github.com/"
end
And ran:
rake gems:unpack

Bada bing bada bang boom!

In addition I found that when trying to use +showgrid with this gem it was pointing to the grid.png image in the wrong place. I had to change the gem in <gem>/frameworks/blueprint/stylesheets/blueprint/modules/_debug.sass, line 1 and line 4.

From: images/grid.png
To: /images/grid.png

Now everything works, I'm on Rails 2.2.2.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
That was just the problem with Capistrano, it WAS NOT A BIG PROJECT it was made big by the guy writing it when really all it had to be was really simple. I'm glad it's gone, I hope it never gets worked on again and I hope myself or someone else finally gets off their rear end and makes something good, like that "The Destroyer" thing which was posted.

I hate Capistrano, through no personal or "emotional" response to the person who was building it, I just think that it is not useful and only gets used because people pile behind things regardless.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Question; but good lord, let me try my best to explain it. :)


I have a users table and a conversations table. I've constructed a conversation_users table to keep track of the last time a user visited a given conversation and some assorted other info that relates the two.

What I want to do is eagerly load the information in this table depending on both which user is logged in and which conversations are currently being viewed. Right now my models simplified look like this:
code:
class User < ActiveRecord::Base
  has_many :conversations, :dependent => :nullify
  has_many :conversation_users, :dependent => :destroy
end

class Conversation < ActiveRecord::Base
  belongs_to :user
  has_many :conversation_users, :dependent => :destroy
end

class ConversationUser < ActiveRecord::Base
  # This table is used to keep a record of the last
  # time a user visited a given conversation
  belongs_to :user
  belongs_to :conversation
end
Right now I can see no way to eagerly load conversation_users except for either by all users of a given conversation or by all conversations of a given user.

What I'd ultimately like to do is add something like this to the Conversation model:
code:
class Conversation < ActiveRecord::Base
  belongs_to :user
  has_many :conversation_users, :dependent => :destroy
  has_one :conversation_user, :conditions => ["conversation_users.user_id = ?", current_user.id]
end
But that I cannot do, I'm certain I've just confused myself maddeningly. Please help!

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I have moved things to the controller like you suggest and added an extra method to the model. Thank you for your help, I'm concerned though it will start to get a lot messier as the project advances forward.

Here's what I've done:
code:
class ConversationsController < ResourceController::Base
  private
  def collection
    if current_user
      conditions = ["(conversation_users.user_id = ? OR conversation_users.user_id IS NULL)", current_user.id]
      @collection ||= end_of_association_chain.find(:all, :include => :conversation_users, :conditions => conditions)
    else
      @collection ||= end_of_association_chain.find(:all)
    end
  end
end

class Conversation < ActiveRecord::Base
  has_many :conversation_users, :dependent => :destroy
  def conversation_user
    self.conversation_users.first
  end
end
There will only ever be one conversation_user for any pairing of both user and conversation, there still doesn't seem to be a way to clarify that in rails. Currently it's all just being written out in custom methods that have a lot of checks and balances to eliminate a corrupt database for something that doesn't seem like it would be so uncommon a thing to need to do.

Something tells me I'm not doing this the rails way and I'd like to, unless this is the rails way and I'm just confusing myself.

Nolgthorn fucked around with this message at 23:00 on Mar 12, 2009

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
that is what im doing.

The problem is i want to eagerly load the table for items on the index, which isn't really a problem... just a concern that it's not the best way to do it. Thats all, and Im obviously doing something that isnt common after all so no worries.

:(

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
It isn't the owner... I think we're falling way off base here of what I've been trying to do, though skidooer's initial suggestion was good.

Remember that the conversation_users table is there to keep track of the last time a user visited a given conversation and some assorted other info that relates the two. But I guess what I didn't clarify was that a record gets added or updated on this table once every time any user visits a conversation. There is one conversation_user record for each pairing of a conversation and a user, where the user has visited the conversation.

The solution I am using based on Operation Atlas' first suggestion works, but I was aware that Active Record was capable of searching based on two indexes because I know of has_many through and I know of has_and_belongs_to_many...

That's all I really wanted was to pair up the current user and a list of conversation objects then be able to eagerly load the conversation_user data for each conversation where available.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
That's what I'm already doing though.

I really appreciate all the help with this but please start talking about something else guys. I'm already doing what people are suggesting which tells me that I'm already doing it the best way I can, or I'm doing it the way I should.

:)

Thanks to everyone though.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Ok gently caress it, here's what I did instead.

It's a tale of woe and sadness, a knight's frustration and suffering. Many castles have fallen, many people left a bitter wreck at the side of the road.

The amount of complication that had arisen out of all this became too much for my little medieval brain to bear, you're just going to have to trust me that it started to get pretty crazy and all for what I kept asking myself.

So I've exposed my current_user object to the model using cattr_accessor, which is something yes I know I am not supposed to do.
code:
class User < ActiveRecord::Base
  has_many :conversations, :dependent => :nullify
  has_many :conversation_users, :dependent => :destroy
  acts_as_authentic
  cattr_accessor :current_user
end

class ApplicationController < ActionController::Base
  before_filter :put_current_user_into_model

  private
    def put_current_user_into_model
      User.current_user = current_user
    end
end

class Conversation < ActiveRecord::Base
  belongs_to :user
  has_many :conversation_users, :dependent => :destroy
  has_one :conversation_user,
      :conditions => ["user_id = ?", (User.current_user ? User.current_user.id : nil)]
end

class ConversationsController < ResourceController::Base
  private
  def collection
    @collection ||= end_of_association_chain.find(:all, :include => [:user, :conversation_user])
  end
end
This works like an absolute dream, I could not be happier, it's about 100% workload off my mind and you'll have to trust me on that. OOP and VMMPY and OSYYTR all be damned, this is too elegant to not use.

This is just so much off my mind. :knight:

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
It feels like Rails 3 is just around the corner. I'm at a loss, I have a large project I want to get started on but I'm not sure if I should use the latest from the Rails 3 repository and then update as it goes or just use 2.3.

I wonder if I will be able to more or less migrate my 2.3 app into a Rails 3 application later on.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
My concern was mostly that Rails 3 might be vastly different from 2.3. I would not be able to migrate a Rails app to a Merb app easily for instance, it would be more or less a rewrite.

I guess I'll stick with Rails 2.3, you're right that it will still be supported for quite a while.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Not really a question I just wanted to say the anticipation for Rails 3 release is killing me.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I decided to use a unique name column to look up objects on one of my models. I want to be able to change this unique name.

code:
class Page < ActiveRecord::Base
  validates_uniqueness_of :name
  validates_format_of :name, :with => /^[a-zA-Z0-9_]*$/

  def to_param
    name.parameterize
  end
end

- form_for(@page, :url => page_path(@page)) do |f|
  = f.text_field :name
  ..etc
If validation fails submitting this form to edit the name, path generated also changes.

code:
<form action="/pages/index_2" class="edit_page" id="edit_page_201" method="post">
Becomes.

code:
<form action="/pages/index invalid name" class="edit_page" id="edit_page_201" method="post">
This means the next time that I try and submit the form it directs me to the wrong place. How can I get it to behave the way I want, since it can't lookup any records with the invalid name.


Edit: hmm

I suppose I could use something like this.

code:
- form_for(@page, :url => page_path(Page.find(@page.id))) do |f|

Nolgthorn fucked around with this message at 02:15 on Apr 3, 2010

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I really appreciate it NotShadowStar. But I've merely simplified all that stuff you wrote, so that it would be easier to answer my more specific question.

I'm already using REST and standard restful controllers and error_messages_for and a form partial and those things. When validation fails, the page is refreshed. It doesn't really go to an entirely different page, the update action re-renders the edit page again. Even though a happy bright red message box does indeed appear the form's action parameter changes and points to an incorrect path based on the modified name field in the form.

This is because the name field is used to render the model object as a parameter in my model. But I don't really know how to fix it. The best thing would be if I could pick and choose times that to_param renders as the name, or renders as a id.

Nolgthorn fucked around with this message at 21:10 on Apr 3, 2010

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
^^ This.

Totally answers my question, it's genius! I totally forgot model_path() accepts strings, integers and the like... this'll only take a bit of changes.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Hello.

The solution may be just out of my reach... I've slept on it, woken up and still remain confused about how to solve it. :wall:


I have three models

:page, :chunk and :cut_text

Chunk is a crazy model. It has two polymorphic associations

:chunkable and :cutable

:page is a :chunkable and :cut_text is a :cutable. :chunk is acting right now as sort of a habtm between :page and :cut_text.

:cut_text and :chunk are both created at the same time when creating a :cut_text.

:chunk contains a few nested attributes that appear on the :cut_text form.

When creating a new :cut_text;
'accepts_nested_attributes_for :chunk' allows :chunk attributes to be applied to a new :chunk.


I've added validation to :chunk which validates both :chunkable and :cutable have been applied.
code:
class Chunk < ActiveRecord::Base
  belongs_to :chunkable, :polymorphic => true
  belongs_to :cutable, :polymorphic => true

  validates_presence_of :chunkable_id, :chunkable_type, :cutable_id, :cutable_type
  attr_accessible :background_color, :background_image
{etc..}
end

class CutText < ActiveRecord::Base
  has_one :chunk, :as => :cutable, :dependent => :destroy

  attr_accessible :content, :chunk_attributes
  accepts_nested_attributes_for :chunk
{etc..}
end
In CutTextsController I call '@cut_text = CutText.new(params[:cut_text])' and '@cut_text.save' in 'def create'.


It is necessary I specify '@cut_text.chunk.chunkable = @page' somewhere as to ensure the new nested :chunk object contains a :chunkable object and passes validation before @cut_text can be saved successfully.

But the chunkable attribute is not accessible due to attr_accessible which is trying to prevent users from modifying the value.

I cannot call update_attribute after the record exists as the record will never validate.


How do I tell rails that it's ok to set the :chunkable attribute before saving the :chunk, while still using attr_accessible and validation?

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Operation Atlas posted:

You can't. The solution is probably to just be careful in the controllers (setting the value in the hash yourself) and take out attr_accessible.

I realized there is probably no reason to use validations on something that users cannot access. I chose to put the changes inside of a transaction ensuring both objects are accounted for.

Nolgthorn fucked around with this message at 22:53 on Apr 17, 2010

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
In the application I'm working on before showing things like last names, email addresses, etc. I have it set up so that privacy settings are assessed that ensure a user actually wants their email address or last name to be visible. The problem is that often a whole unnecessary query that traverses backwards through the user model from within the privacy model is run: "self.user".

Is there a way to magically give the user object into the privacy model when I reference the privacy object so it doesn't have to traverse backwards?

Having trouble solving this logic experiment, or else there is something very simple I just don't see!

code:
class User < ActiveRecord::Base
  belongs_to :privacy, :dependent => :destroy

  def display_name
    return self.firstname unless self.privacy.show_lastname?
    self.full_name
  end
end
code:
class Privacy < ActiveRecord::Base
  has_one :user

  def show_lastname?
    [false, true, self.determine_friend?][self.perm_lastname]
  end
  
  def determine_friend?
    return true if self.user.id == current_user.id
    return false unless relationship = self.user.relationship(current_user)
    relationship.is_friend?
  end
end

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Wow, thank you dark_panda. That is pretty much exactly what I was looking for, I can go back and clean up some of my code now.

While Rails is using id columns to look up relational objects, the User object is exposed to my users through a different unique identifier. So the user objects weren't being retrieved by id most of the time, therefore are not getting cached.

Is there a patch to make this whole inverse_of functionality on by default in the works currently? Is it memory expensive, too much bloat?

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

plasticbugs posted:

I had a column in my model named "Type".

I've done this or similar a lot with Rails.

One time it was a little obscure one and a problem didn't crop up with it until weeks later with some weird insane error on one specific specialized action. Now I use a thesaurus to pick most of my names.


A couple of current favourites are:

Crowd, Stream, Disclosure, Party, Participant, Actor, Candidate, Rival.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I believe the current rails 3 auth favourite is devise. http://github.com/plataformatec/devise

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I assume since I have been using Rails (especially Rails 3) for a little while now that I am spoiled beyond repair with regard to ease of web application development.

What I am looking for after having constructed a complicated application, is some way of analyzing and picking at what is being rendered into HTML for me. There are partials everywhere, coupled with helpers, coupled with information spread across lots of different database tables. There are several places where database information is being eagerly loaded and other places where the assumption is that the page information is cached etc.

Are there any gems available that will sort of... make it easier to see exactly what is going on?

The reading I have done has led me to believe I need to write performance based tests, but those don't really tell me everything I am hoping to more easily know. Maybe some kind of gem that monitors everything my application is doing and then creates a big beautiful page that details where all of the bottlenecks and rendering hogs are.

Is there something like that?

code:
Rendered content/recent.haml within layouts/application (1080.1ms)
Completed 200 OK in 1517ms (Views: 1124.4ms | ActiveRecord: 15.2ms)
:ohdear:

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

8ender posted:

There is NewRelic:
http://www.newrelic.com/RPMlite-rails.html

Its pricey if your app isn't out making lots of cash but invaluable. You can analyze individual queries, see a log of errors, performance stats, the works. It even emails you a nice weekly summary. I didn't have a chance to really try it out thoroughly before my Gold trial came up, so I'm stuck on Lite until we release the app that using it. My experiences with Lite have been positive though. Lite doesn't tell you much but you are able to get a general idea if the server is coping well with the average user load, which is really important to us as the app is on a VPS that we can dial up when we run out of capacity.

Interesting. Thank you for giving me a jump off point, I didn't realize that such a thing would be so expensive. The few automated options available seem to be fairly... well dishonest. I don't think that the software only being able to update data once every 10 minutes unless I upgrade to a much more expensive version is very accurately reflecting their costs for the service, for example.

For these prices I feel like just using my brain, going through the code and reading logs manually instead.

Adbot
ADBOT LOVES YOU

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Anveo posted:

You can also just use it locally in development mode. Just browse a few pages and then go to /newrelic. It will at least give you more context than just eyeballing the code and logs.

I'll try to keep you guys up to date on what my method ends up being, I'm going to try and avoid newrelic for now. It seems to be the go to application for my specific use request, but I'm feeling a little bit heretic.

Thanks everyone for the advice, I really appreciate it. Serious.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply