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
Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

phazer posted:

When I use before_filter :login_required I get an undefined method error.

code:
NoMethodError (undefined method `login' for #<BandsController:0x412bf8f4>):
I followed that tutorial exactly. Could it have anything to do with my version of Rails? (2.1.2)

edit:

OK I don't know what's going on, but I am doing this on Media Temple hosting, and I thought well maybe I should restart the application, maybe that will get some of my changes to take effect. So I went to restart it and the mongrel.pid file got deleted and now my drat application won't start.

Media Temple support was no help last time I had this problem. (we don't support custom code, etc. well what's the point then?) Can anyone help?

1) I have a feeling that in your action you are trying to muck with a "login" variable that is undefined- if there is no local variable defined, it will look for it in the next best place- a method on your BandsController instance (where it can't find it because it doesn't exist, so it tosses).

The important thing to remember here is that Rails controllers aren't magic. Your "actions" are just methods in a class. Each action is an instance method, and "self" inside of actions is the instance of your controller class. (If that doesn't make sense, Google "Object-Oriented Programming") Try to think of what you're doing inside of a Rails action as a normal method call, in a normal class only your return is a little weird (You are quite literally returning your render/redirect method call).

2) The media temple stuff has nothing to do with this. You should be doing all of this stuff locally anyways. Only once you get a working application should you be deploying to a webhost. For some reason I'm assuming you're on windows- don't they have one-click Rails installs and whatnot? Use those.

Adbot
ADBOT LOVES YOU

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

phazer posted:

I did have a working application before I deployed. In fact, it was working AFTER deployment until this restart issue. It is Media Temple. They said my Mongrel gem is corrupt and they don't know why. And I'm on OS X.

Well, to be sure, the mongrel pid problem and the nomethoderror problem are two different problems. If it is working locally but not working remotely on the same code, all I can say is make sure you've run your migrations.

The chances of your mongrel gem being corrupt are slim to none. The mediatemple people have no idea what they're talking about. How did you do the restart? Is this a full-on VPS or are you stuck on some shared thing?

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

phazer posted:

I got:

code:
Usage:
  kill pid ...              Send SIGTERM to every process listed.
  kill signal pid ...       Send a signal to every process listed.
  kill -s signal pid ...    Send a signal to every process listed.
  kill -l                   List all signal names.
  kill -L                   List all signal names in a nice table.
  kill -l signal            Convert between signal numbers and names.

Just do
code:
ps aux | grep mongrel
, find the PID of your mongrel, and then kill it. Then start it again.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

phazer posted:

Same exact error. Like I said, MT support is on it... just waiting to hear back.

Ugh. I'd ditch MT if I were you. I had a deal for free MT hosting for a year and after 6 months decided to pay for hosting rather than keep using them. They're really quite awful.

Get a $20 account at Slicehost. Sure it might be a bit more, but you'll be saving yourself so much time by not having to deal with the crap that MT forces you through.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

atastypie posted:

Do you mean MT in general, or MT specifically for Rails?

MT for Rails. If you use PHP, I'd imagine it would be just fine.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

phazer posted:

I will say deploying an existing rails app on Media Temple was WAY easier than dreamhost. (before i decided to restart the application)

Hah, yeah, dreamhost is a whole other can of worms.

I'm hoping that these hosts get their act together soon and start using Passenger. There's no reason not to at this point- it is so much better for pretty much any setup. Using a whole VPS for a toy app is overkill.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

Flobbster posted:

Speaking of deployment...

I've been working on my first RoR application for the past month or so, and hope to deploy it in a couple weeks. (I haven't even approached it yet, I've been doing everything in development.)

In a couple of the RoR books I've been referring to, everything I've read makes deployment seem like so much unnecessary complexity (setting up an SVN repository, Capistrano...), and it has my eyes pretty much glazing over, though partly I'm sure because I'm not ready for it yet.

As I go back to RTFM some more, I'm hoping someone can just give it to me straight -- is it possible to deploy a site simply by uploading my app's directory tree (and the SVN stuff is just for things like managing updates/changes more easily), or do I really need to deal with all this extra cruft for even the most basic site?

You can set Cap to deploy_via :copy, which is what I recommend for the time being. I think there are a couple of plugins to capistrano which will allow you to do rsync, which would be better.

Obviously using source control and deploying from there is the way to go, but this should get you over the hump.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

dustgun posted:

Route generation question time:
url_for, through polymorphic_url, can take an activerecord object (or group of them) and turn it into a route. Like url_for(Post.first) -> /post/1 by calling post_url which is a named route function generated by saying that Post is a resource. Or something. I don't use resources so I'm just guessing on that bit, but I do know the route generated would be something like map.post('/post/:id', :controller => 'post') and then some magic happens when Post.first is passed in :id gets matched with the route parameter.

Before I really dig into routing's code, what I want to know is if there's a way to use named routes, url_for and AR records in a way that works without needing the :id parameter. Like if I have...
code:
class Person < ActiveRecord::Base
   def first_name
      fullname.split(' ').first
   end
   def last_name
      fullname.split(' ').last
   end
end
and map.person('/person/:last_name/:first_name')
is there a way to do url_for(Person.first) -> /person/schmoe/joe without having to explicitly say url_for(person, :first_name => person.first_name, :last_name => person.last_name)?
It figures out that it needs to call person_url, but it doesn't dig into the model to see if last_name and first_name are able to be dropped into the route. Instead, it tries to positionally assign the arguments to url_for on top of the route parameters, so you end up with :last_name => #<User id: 1, fullname: "joe schmoe">, :first_name => nil.

Does what I'm asking make sense? Am I totally misunderstanding something?

Use to_param

code:
class Person < ActiveRecord::Base
  def to_param
    fullname
  end
end
And make sure you modify your controller to find_by_fullname instead of find(_by_id).

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

dustgun posted:

Oops, I should have mentioned I knew about to_param.

Given url_for(User.first) in a view:
I could use to_param to make it a little prettier: /person/:id as a route, giving me /person/joe-schmoe.

What I want is /person/:last_name/:first_name as a route, giving me person/schmoe/joe. Doing that requires url_for et al to look at the object I passed in beyond just taking the result from a to_param call.

I guess the polymorphic url helper wasn't really meant to be used like this, but it sort of surprised me it didn't do this :-\

Any particular reason you want it to be person/schmoe/joe? Purely aesthetics? Going down this path seems like bad news to me.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

dustgun posted:

It was a somewhat contrived example that I didn't fully think through.

Here's the more practical one: I have a table full of CIDRs, represented by 2 integers - start_ip and end_ip. Having a route like /cidr/1 is dumb, as is /cidr/22605312/22605567 - I want cidr/1.88.238.0/24. It's easy enough to do as long as I use cidr_path(), but I really really want url_for to do this automagically because there are a bunch of cases where I get a list of objects back from something - say, search results - and they can be all different kinds of data. Country Names, Corporations, CIDR owners, Domain Names, etc. Right now the only way to iterate over those results and use the correct _path() method would be to do something like skidooer suggests.

I mean, that wouldn't be the worst thing in the world. It just feels like the current polymorphic routing is tantalizingly close to what I want :(

Why not just escape/sub the / before the mask? The only thing happening here (I think) is that the slash in a CIDR just happens to be the same character as a URI delimiter.

I see no problem with "/cidr/1.88.238.0|24" or something similar. Just gsub in the controller to get it to 'proper' format.

(I know this isn't what you're really looking for, but I'm a sucker for shortcuts.)

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

phazer posted:

I'm using attachment_fu and rmagick to create an application for uploading PSDs and I'm unable to find, via google, a solution that converts the file into JPGs for making lightbox previews of the PSD. (I still want the PSD stored on the server, too, though.)

Thanks for any direction on this.

There's a tool that comes bundled with ImageMagick called 'convert'. Call from the command line "convert x.pdf x.jpg" and you're golden.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

jonnii posted:

He said psd, not pdf. If I remember correctly, ImageMagick can convert PSD files, but I'm not sure how up to date their support is. Worth a shot though.

Oh poo poo you're right. convert should still work with PSDs, but it seems kind of sketch.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

Flobbster posted:

I'm keeping the 'show' action separate and protected behind the authentication :before_filter because it's intended to be used in the admin section of the site (along with the other actions) to show additional private information, with a different layout. 'display' is essentially a simplified version with a different layout, intended for public viewing.

Dude, that's what if statements are for. Seriously.

code:
def show
  @artwork = Artwork.find(params[:id]
  if logged_in?
    render :action => "show"
  else
    render :action => "display"
  end
end
Off-topic, but bugs me: Don't bother with that respond_to crap unless you have more than one format that you're responding to. In the meantime it is just adding in noise.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

Flobbster posted:

I'll rename it "enlarge", so we stop getting hung up on the synonym and overlooking the actually problem here, which is why an action method isn't getting called.

You know what, that would fix it. "display" is a preexisting method in ActionController.

Edit: Oh, there was a new page I didn't see and you found that out already. Awesome.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

phazer posted:

How do I put links in a boolean output? Can I? There must be a way.

I prefer to do

code:
<%= link_to_deactivate_here if category.active? %>
<%= link_to_activate_here unless category.active? %>

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

phazer posted:

No clue.

Look at the Javascript that Rails is pumping out, and see what's wrong with that.

I hate RJS for just this reason.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought
So... Merb and Rails are to merge for Rails 3. Thoughts, everyone?

Personally, I'm kind of pissed off. There's a reason I stopped developing in Rails and moved over to Merb. The way Rails handles rendering is enough to make me hate the thought of going back.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

Pardot posted:

Yeah we'll see how it goes. If it ends up being the best of the two, that'll be great.

From what I've talked to people, Rails is going to be like Merb, where the default stack is just going to be the current Rails stack. But you could swap out AR for datamapper, or you could easily switch to jquery without extra plugins like you need today.

For rails, they get some smart people on the team from merb, and don't have to worry about merb killing them. For merb, they get, what, name recognition? I don't really see how this move helps the merb team.

I'm all in favor of choice, but since I already had that with Merb, I don't really gain anything.

I'm not sure why this is good for Merb, either. I, personally, didn't see the competition between the two frameworks as a bad thing.

dustgun posted:

I was just about to start playing with merb today but now it feels horribly moot :(

It might actually benefit to start learning Merb. It'll get you prepared for Rails 3, which, after reading more, might be very heavily impacted by the Merb merge.

Overall, this seems like it is great for Rails people and "Meh?" for Merb people. I haven't seen a Merb person (aside from the Core team) who is particularly excited about this.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

Nolgthorn posted:

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

Oh. Gosh. Where do I start?

First thing's first: Controllers should be skinny. Something is wrong if your controller has any logic that is concerning anything other than these things: Rendering, redirecting, security, requests, sessions or parameters. "Business logic" has absolutely no place in the controller. Get that stuff to the model, and I think you'll find a lot of the complexity will melt away by itself.

Secondly, this stuff is so much easier to test once it is in the model. You should have comprehensive unit tests built around this stuff. That way, you KNOW it works, instead of the "test and refresh" method of "testing" your code (Where you THINK that it PROBABLY works). If it doesn't work, you know exactly what is wrong.

Thirdly, fetching your @forum_thread should probably not be in a before_filter, but if it is, verify_is_owner should be called along with it. That way, by the time you get in the method body of "update" you know everything is kosher with permissions and you can just keep going.

Fourthly, you should definitely be using a different attribute name than updated_on. You're not really tracking updated_on in this case, so rename the dang thing.

Fifthly, use && instead of "and". They are NOT the same thing. They have different precedence.
code:
a = 'test'
b = nil
both = a && b       # both == nil
both = a and b      # both == 'test'
both = (a and b)    # both == nil
Sixthly, something smells when you're doing update_attributes on two different objects in the same request. I'm not exactly sure what's going on with your app, but it is unlikely that doing it this way is the best and cleanest way to solve the problem. I think I've only done that once out of the >500 actions that I've written.

I don't mean to harsh on you, but it's best that you learn these conventions as quickly as possible. It's better for you, and for anyone who might have to read your code in the future.

(Also, in response to Hammertime, I never use save!. I'm not sure if it is just preference or what, but I like if->else over begin->rescue)

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

Pardot posted:

What do you guys like better: braid or git submodules? Both have been frustrating.

I gave up on submodules. I just commit everything straight into the repo. You suffer from a dirtier history, but it is so much easier to deal with and deploy.

I might try it again though. The primary reason why i gave up on it was because I was still using git-svn (for Trac), and submodules don't work at all with git-svn.

I've never used Braid... How is it different from Piston?

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

mister_gosh posted:

I'm considering learning and writing a RoR program(s) basically for the hell of it, to learn it. I have a need for a web application that is database dependent (Oracle 10g). If I do not go with RoR there is no way I'd even consider PHP, I'd use Java, JSP, Javascript, etc.

So, given my background and disapproval of PHP, does this sound like a wise use of my time? I'm curious just so I can put another skill under my belt, but that's probably the wrong reason to get into this.

Also, can RoR scripts be runnable from a command line if I had such a use? Can it communicate with COM objects?

Learning a new language is never a poor use of your time.

This is, also, exactly how I got started with Rails. The Oracle adapter is stable and works well.

Running Rails scripts from the command line (really, you're likely to just be using ActiveRecord from the command line) is easy. The best way to do it is with Rake tasks. There should be a guide or something out there if you want to Google it.

If you just want to interact with the Oracle database with command-line scripts and have no interest in the Web part of it, you might want to start out with just Ruby and the ActiveRecord gem. Create some simple scripts, and just "require 'activerecord'" and start going. There's no need to have the big directory structure and all of that if you don't need it.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

Sewer Adventure posted:

The thing about that strict MVC enforcement poo poo is sweepers don't work when I'm using cron jobs to call script/runner to invoke a Model.method

You might want to look into Observers. That way you can keep strict MVC separation but also have it work with models alone. I've used Observers for permissioning for the same reason, and it worked really well.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

mister_gosh posted:

I'm watching a Rails screencast from peepcode (Rails from scratch part 2). I have tried to watch it a couple times now and 3 minutes in I always turn it off and try to read other resources to confirm something.

He states that with:

code:
ruby script/generate scaffold ModelName
will create a scaffolding for a table name. I assume that means that the model will be "book" if the database table is named "books".

He also states that this puts together a migration that will build these tables in your database.

The application I hope to build while learning Rails is to work with an already existing, and partly 3rd party, database. This database does not have "s" at the end of each table name (am I breaking some cardinal RoR rule here?).

I'm thinking I probably don't want to build a scaffold as the migration is not needed, but then I feel like I'm missing the point here. Does an entire RoR application have to include the creation of almost proprietary type tables for Rails to work with? They can't already exist? By not building a scaffold, am I missing a major point in the ease of building web apps using rails?

I just started learning, so feel free to just say "keep reading" if my questions make no sense.

You don't have to use the generator, it is just easier.

In your case, just create a file in app/models called "book.rb" and start it thusly:

code:
class Book < ActiveRecord::Base
  set_table_name "book"
end
And then you're good to go. If you want unit tests, go create the file in test/unit and create the fixture in test/fixtures. The generators don't do anything magical.

Edit: Also, testing will be difficult in this scenario and I honestly don't know how you'd be able to do it.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

Hop Pocket posted:

Regarding restrictions -- a lot of it has to do with whether or not there will be different applications hitting the same database. In that case, it makes a lot of sense to back up your model validations with database constraints. That way at least you can be sure that your database will not be left in some crazy state by a non-Rails process that also happens to be writing to it. I'm currently working on a project that has a DB that both the Rails processes and a Java server process access, and it's pretty essential that the constraints be definitively defined at the DB layer. Now, why some would assume that to be the default when creating migrations, I suppose it's really just a matter of preference to the coder.

I believe the reason that this is done is with error handling. Databases give lovely and sometimes hard to determine error messages for constraints. Not saying it couldn't be done, but a lot of work would have to be done for each adapter to make it viable.

I think this is something that will eventually come to Rails, but not for another couple of years still.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

Nolgthorn posted:

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:>

Try out Vlad. http://rubyhitsquad.com/Vlad_the_Deployer.html

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

savetheclocktower posted:

To each his own, of course — HAML has many zealous users and I'm sure it is well-made — but the trend of applying a Ruby frontend to everything drives me insane.

It's bad enough having to re-learn the best way of doing things every six months when I revisit Rails. People keep inventing their own goddamned DSLs for everything and I don't know how they keep them all straight.

I guess I like the ERB approach to things: HTML with splashes of Ruby, rather than RUBY EVERYTHING.

Eh? Haml isn't any more Ruby than ERB is. Haml is a re-implementation of HTML using a more terse syntax. There are Haml libraries for Python, and several other languages I believe.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

manero posted:

Oh great, no more capistrano?

I hope the community picks up development. There's a decent flamewar going on over at Hacker News about it.


Dropped like a ton of bricks. Capistrano is useful and all but gosh way to abandon.

"Let the community decide" sounds awfully a lot like "Let the market decide"

I think someone will most definitely pick it up. There are too many people using it (not even just in the Rails community) for it to die, really.

I think Jamis handled this poorly. He should have asked for help a lot earlier, and he could have switched to a "project manager" kind of role a long time ago, kind of like DHH with Rails. For whatever reason, Capistrano was always viewed as "his" project, and bug reports, patches, etc always went through him. That's why he got burnt out, and I think that burn out was completely avoidable.

That said, maybe Capistrano should die. It is pretty much a reimplementation of Rake, only less awesome. Maybe this will get people to consider alternatives like Vlad more seriously. There's no reason for a deployment solution to not use Rake. Jamis is a great developer, but his projects are always way too grandiose.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

Nolgthorn posted:

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:

If I'm understanding you correctly, I think this will work:

(Example for Conversations#Show action)

code:
Conversation.find(params[:id], :include => [:conversations_users], :conditions => {:user_id => current_user.id})
If that doesn't work, I apologize, I actually haven't been doing much Rails work lately. But it should be somewhere in the area.

If what you want is this stuff to be automatically loaded in the model, I think you're looking in the wrong place.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

Nolgthorn posted:

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.

Well, the "Rails Way" is has_and_belongs_to_many, but you can't use that because (if I read correctly) you have extra attributes you need to keep track of.

I really can't tell what you're trying to do, but you're doing it wrong. You're overthinking it. This is really quite a simple thing.

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
  belongs_to :user
  belongs_to :conversation
end

class ConversationsController < ApplicationController
  def show
    @conversation = Conversation.find(params[:id])
    @conversation_user = @conversation.conversation_users.find(:first, :conditions => {:user_id => current_user.id})
  end
end
That's really all you need. No methods on the model. No extra methods in the controller. Just finding stuff. And definitely no SQL in the conditions.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

skidooer posted:

The "Rails Way" would be to use has_many :through, which is essentially what he is doing, save actually defining the through association.

If I'm understanding his models correctly, you couldn't really use has_many :through in this situation. I think what is going on is that a user can "own" a conversation (they started it, presumably), and that each conversation has an owner (what user started it). If this is not the case, then things change drastically. However, I have been working off of this assumption


Nolgthorn posted:

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.

:(

I think in order to eagerly load your ConversationUser, you'd have to do this in your controller:

If you want to know about only the currently logged in user:
code:
Conversation.find(:all, :conditions => {:user_id => current_user.id}, :include => [:conversation_users])
If you want to know about all users:
code:
Conversation.find(:all, :include => [:conversation_users])

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

Nolgthorn posted:

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.

Sorry, I really tried to be nice about this but you seem intent on ignoring the simple solutions we keep telling you about. So I can't be nice anymore.

You better hope that nobody else has to see that code or ever maintain it, because they're going to have an absolute shitfit.

YOU'RE DOING IT WRONG. That solution violates MVC, is fragile as hell, and is way too complicated. This is the absolute farthest thing from "elegant".

If I had you fix one thing though, it would be this. Do not ever do this. Ever.

WRONG:
code:
has_one :conversation_user,
      :conditions => ["user_id = ?", (User.current_user ? User.current_user.id : nil)]
RIGHT:
code:
def conversation_user(a_user)
  @cu ||= conversation_users.find(:first, :conditions => {:user_id => a_user.id})
end
Never ever call another model on an association declaration. This will blow the gently caress up in production and, besides, is nasty. And please use the hash conditions syntax wherever possible. This "user_id = ?" stuff is completely unnecessary.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

skidooer posted:

That will query the conversation_users table for every conversation row, exactly what Nolgthorn is trying to avoid.

Yeah you're right, but this was the least-bad option of him insisting to have logic in the model that doesn't belong there. In my first reply to him I suggested a load from the controller, which is still the best, easiest, fastest, and most correct way of doing it.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

Lamont Cranston posted:

I'm trying to implement custom 404 pages using method_missing in my ApplicationController. This code:
code:
  def method_missing(methodname, *args)
    begin
      super
    rescue ActionView::MissingTemplate
      render 'error/index', :status => 404
    end
  end
should do the trick but it throws "ArgumentError (no id given)" when it calls super. I know this can happen if I modify the value of "methodname" but I don't. Any ideas?

Why not just:

code:
def method_missing(*args)
That should fix it. Do you need methodname in particular?

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

theEZkill posted:

Yeah I noticed that when I was researching rails this morning- this is for building apps, not running scripts. I just talked to him about it over dinner and he said it was for sure RoR and it's pretty much copy/pasting a script to automate Twitter. What exactly does it do? No idea.

You can have a Ruby script that doesn't use Rails, and call it from the command line.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

KarmaticStylee posted:

what's the best base install when u set up on slicehost?

Debian

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

NotShadowStar posted:

I still don't know what the gently caress the core Ruby team was thinking. They improved the core aspects of the interpreter that were the primary weaknesses, the GC and execution speed, and it was amazing. Then they go and make fundamental changes to the language AT THE SAME TIME. ARGH.

On the other hand, I'm getting kinda good at tracking down 1.9 issues from libraries, fixing them and submitting patches.

A point revision in Ruby is not like a point revision in any other software. Ruby 1.8.0 came out in 2002,, so it has been 7 years since fundamental changes have been made to the language. It is about drat time, whether or not the internals have been overhauled at the same time or not.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

Clock Explosion posted:

I'm trying to set up Integrity using Thin on an Ubuntu Jaunty install for work purposes. I'm getting an error when trying to start the Integrity server that says

code:
 "can't activate rack (0.9.2) already activated rack (1.0)"
I've googled, and have done many things, including trying to require Integrity to use Rack 0.9.2 and Sinatra 0.9.1, as well as requiring gems that come from my own .gems folder (One of the many solutions I read seemed to point the culprit at Sinatra). Right now, I have three rack gems installed (1.0, 9.1 and 8.7, I think), and two Sinatra gems (0.9.1 and 0.9.2). Most solutions that I have seen have the already activated version of rack be the lower version, not the higher version. Any idea on what I can do?

Unfortunately, any specifics I can provide are limited because this machine is at my workplace, which I don't have access to this weekend.

I'm using Ruby 1.8 and Rails 2.3, I believe.

If you can, uninstall the lower versions of those gems, and one of two things will happen: 1) everything will work, or 2) It will give you a more specific error about who is trying to require that version of rack. This has happened to me before with Merb when I was careless about messing with system gems and vendored gems. The Passenger process, in my case, was using the system gem, and my app was trying to load up a different version out of the bundled gems.

Kind of vague, but I hope that helps. These problems are insanely hard to debug.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

Plastic Jesus posted:

Is it possible to load the code for a lambda from a file?

Not exactly what you're talking about, but sweet Jesus my life would be a whole lot easier if you could store blocks in a database. Lisps can do it, why not Ruby?

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought
Upgraded a Merb app that uses a custom Couchdb adapter to 1.9.1 and it was fairly easy. Only two or three fixes were necessary. It gave me a chance to clean up my gem situation, so now almost everything is vendored- my only system gems are rake, fastthread and passenger. Overall I'm pretty happy with it- ordered hashes are great, and I think I'm going to like the new hash syntax. I haven't delved into many of the other changes.

Speed-wise I really can't see a difference. My test suite runs in the exact same amount of time- ~0.8 seconds for unit and ~5.4 seconds for functional. I thought it would cut it down by like 20% but the difference is negligible if it is even faster at all. I suppose most of the time in tests is IO (database, etc), so I don't think there would be much difference regardless of the language.

Adbot
ADBOT LOVES YOU

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

dustgun posted:

I've spent all day trying to get prawnto & prawn to render layouts. I want to shoot myself in the face and I think I'm just going to hack something up so that ... something something and then it works.

In short, someone make a better PDF creation plugin for rails.

What's wrong with pdf-writer?

Magicmat posted:

I know ruby 1.8 but never so much as glanced at 1.9 until I saw how god damned fast it was and that rails now supports it. I know 1.9 has some major, incompatible changes with 1.8, so what's the best way to learn it? Is there a webpage out there with a list of changes, and is that enough to learn 1.9? Or should I get the new 1.9 pickaxe to compliment my 1.8 pickaxe? What about O'Reilly's 'The Ruby Programming Language'? A lot of people are saying it's better than the pickaxe, and it says it covers both 1.8 and 1.9, but it was published 18 months ago, is the 1.9 info still accurate?

There aren't really that many differences. Just update your ruby binary and run your old projects and see what breaks. My main project (~5000 LOC) only had 2 or 3 places that required minor changes. Took maybe 30 minutes to upgrade. The biggest gotcha had something to do with require and load paths, but I can't remember the specific problem at the moment.

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