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
rolocroz
May 21, 2004

Do me a favor. Say a prayer!

savetheclocktower posted:

You couldn't unselect ScITE? That's the only unnecessary thing it installs, if I recall correctly, and you can opt out of it.

Oh, I guess that is all it is. Thanks!

Adbot
ADBOT LOVES YOU

Hop Pocket
Sep 23, 2003

I need to do a left join on a table in an AR query to select either joined rows that are NULL (where the association did not exist) or where there is a certain value (in the case that the association did exist).

code:
events = Event.paginate(
:per_page=>4,
:page=>page,
:joins=>"LEFT JOIN votes ON (events.id = votes.event_id and 
      votes.user_id = #{user.id})",
:order=>'events.created DESC',
:conditions=>['((votes.dig = 1 OR votes.dig IS NULL) AND votes.user_id = ?) 
      OR votes.id IS NULL', user.id]
)
The problem here is that the fields from the Vote join are polluting the Event. In this particular case, let's say that there are no Votes at all. The result set coming back from mysql has NULL for each Vote id, as it should. However, AR is populating that id field from the Vote into the Event model.

This means that each Event coming out of this query either has a null id or the id of its associated Vote. I suspect that it's a problem with the result set coming back from MySQL. The column names for the Event id and the Vote id are the exact same name: id.

Any ideas?

note: I am using will_paginate, and I tried this query using the straight up AR find(:all, ....) with the same results.

EDIT 2: Hooray! :select => "events.*" seemed to do the trick.

Hop Pocket fucked around with this message at 22:58 on Dec 10, 2007

skidooer
Aug 6, 2001

Hop Pocket posted:

Any ideas?
If I'm understanding you correctly, you want to specify the select statement as well.
code:
:select => 'events.*'
Also, as a style note, you should move most of those details into the model. That stuff doesn't belong in the controller.

asveepay
Jul 7, 2005
internobody
Soooo...how many other people are really unhappy with the complete lack of documentation/guidance with 2.0? basically all of my books have become obsolete, so, yeah, kinda pissed.

skidooer
Aug 6, 2001

asveepay posted:

Soooo...how many other people are really unhappy with the complete lack of documentation/guidance with 2.0?
There's really nothing in 2.0 that's groundbreaking for someone who has already been using Rails. Most of the new features were already being used by most people through their respective plugins in 1.2. 2.0 just brings them into core. If you've been following Ryan's Scraps and/or the development feed you'll already be well versed in the changes.

But I believe that people who are just trying to learn Rails now are probably suffering from the problems you mentioned. For whatever reason, the whole community Rails once had that would help in this area seemed to die out around the 1.1 release. But I guess as a community project, anyone can step in and provide what is missing if they feel it's a problem.

Al Azif
Nov 1, 2006
Are there any guides for moving an application from 1.2 to 2.0 yet? I know there's a script that does some basic compatibility checking.

asveepay
Jul 7, 2005
internobody

skidooer posted:

stuff

Thanks, skidooer, those links will come in handy. I'm not really just learning rails but I'm still at a beginner stage. I had completed a lot of work on an application and then 2.0 released just as I realized I had to rewrite a significant chunk of my app. So I thought it would be good to just start over using 2 and then reimport code where I could. However since I never used any of the plugins that have been folded into the 2.0 core it's a bit confusing having to cobble together information from the various mailing list postings. for instance, i had no idea .rhtml files had gotten the .erb extension till I saw some screencasts using this convention. also the model_path convention and <%=h blah %> was not one I had seen before either. Right now i'm basically forced to build portions using scaffold and then modifying that, which is not easy, especially sinc the API documents seems to also be not yet updated.

asveepay fucked around with this message at 13:09 on Dec 16, 2007

Xgkkp
Aug 20, 2004

by Lowtax

skidooer posted:

But I believe that people who are just trying to learn Rails now are probably suffering from the problems you mentioned.

Hello!

Truth be told I sort of learnt the basics a year ago, but have promptly forgotten everything. I'm managing, but I'm sure I'm not doing stuff the 'Rails 2.0' way.



Anyhow, I have run into a small problem: I'm making a site, with lots of static pages and then a couple of ruby pages for management and registration. How do I integrate the two? I don't want to have to make separate views for every single page (or dynamically generate them on every view with link_to's), but I can't just put in static pages and link to them normally, because then if I do relative links depending on which controller/method I am in they wil be invalid.

I can't do absolute links either, because that would presume that they are on the server root (.com/xxx) which is not guaranteed, and probably not the case.

Hammertime
May 21, 2003
stop

asveepay posted:

I had completed a lot of work on an application and then 2.0 released just as I realized I had to rewrite a significant chunk of my app.

If you have a moment could you expand on what is the cause of the rewrite.

I've got a project sitting at 1.2.6, but was hoping to seamlessly upgrade to 2.0, I didn't realise there were any changes that would cause a re-write of a section.

Hammertime
May 21, 2003
stop

Xgkkp posted:

Anyhow, I have run into a small problem: I'm making a site, with lots of static pages and then a couple of ruby pages for management and registration. How do I integrate the two? I don't want to have to make separate views for every single page (or dynamically generate them on every view with link_to's), but I can't just put in static pages and link to them normally, because then if I do relative links depending on which controller/method I am in they wil be invalid.

Can you just put it in the /public/ directory, I haven't found what I'm looking for yet, but there's probably a way of getting the application root directory (as a foundation for making your links) out of a config variable(that you may have to set manually).

Hop Pocket
Sep 23, 2003

This might be more of a scriptaculous question, but I can't seem to get my animations that my RJS template return to execute serially. In other words, they seem to always run at the same time. Is there a way to get any visual_effect to run only after the previous one has finished?

Evil Trout
Nov 16, 2004

The evilest trout of them all

Hop Pocket posted:

This might be more of a scriptaculous question, but I can't seem to get my animations that my RJS template return to execute serially. In other words, they seem to always run at the same time. Is there a way to get any visual_effect to run only after the previous one has finished?

This is something that has begun to annoy me lately. My game uses a lot of scriptaculous and the best way I found to do things serially is to use the page.delay(seconds) command that uses a block.

code:
page.visual_effect :fade, 'something', :duration => 1.0
page.delay(1.2) do
  page.replace_html 'something', 'HELLO'
  page.visual_effect :appear, 'something'
end
The problem is, I've found in the real world that sometimes the delay will execute before the first visual_effect has finished (usually on slow computers). In the example above, this will cause the div to not appear properly as it will be updated before it's hidden.

If you're coding in pure javascript, Scriptaculous allows you to execute events once the animation has finished, however there is no API for doing this in RJS.

skidooer
Aug 6, 2001

Al Azif posted:

Are there any guides for moving an application from 1.2 to 2.0 yet?
Run your test suite and fix anything that fails. Unless you've been monkeying with the Rails internals, or using deprecated methods (which you would have seen warnings for in the logs), you probably won't have to do anything.

asveepay
Jul 7, 2005
internobody

Hammertime posted:

If you have a moment could you expand on what is the cause of the rewrite.

I've got a project sitting at 1.2.6, but was hoping to seamlessly upgrade to 2.0, I didn't realise there were any changes that would cause a re-write of a section.

I'm not rewriting because of 2.0 (not really, anyway) but I started trying to integrate a feature much too late and I couldn't figure out an efficient way to insert it without breaking everything and having to debug. So i thought I'd start over and hopefully be able to use the upgraded parts of 2.0 for a more efficient/bleeding-edge app. I can't think of any portion of my 1.2.6 application which doesn't still work fine aside from a few deprecation warnings, but definitely trying to do things the 1.2.6 way is not flying too high in 2.0 land.

ikari
May 17, 2003

Yeah, pretty much.

Hop Pocket posted:

This might be more of a scriptaculous question, but I can't seem to get my animations that my RJS template return to execute serially. In other words, they seem to always run at the same time. Is there a way to get any visual_effect to run only after the previous one has finished?

Grob posted:

If you're coding in pure javascript, Scriptaculous allows you to execute events once the animation has finished, however there is no API for doing this in RJS.

http://wiki.script.aculo.us/scriptaculous/show/EffectQueues

You can use EffectQueues to get that behaviour, they can sometimes behave strangely but it's likely what you want.

Evil Trout
Nov 16, 2004

The evilest trout of them all

ikari posted:

http://wiki.script.aculo.us/scriptaculous/show/EffectQueues

You can use EffectQueues to get that behaviour, they can sometimes behave strangely but it's likely what you want.

Interesting, I didn't know effect queues were supported by RJS!

Having said that it wouldn't solve the problem I had above as updating an element isn't an animation, but it would solve the initial question :)

ikari
May 17, 2003

Yeah, pretty much.

Grob posted:

Interesting, I didn't know effect queues were supported by RJS!

Having said that it wouldn't solve the problem I had above as updating an element isn't an animation, but it would solve the initial question :)

http://wiki.script.aculo.us/scriptaculous/show/EffectsTreasureChest

Check the Effect.QueueThis section, it may be what you're looking for. I haven't used it myself but it looks like it'll let you queue up an arbitrary function.

savetheclocktower
Sep 23, 2004

You wait and see, Mr. Caruthers. I will be president! I'll be the most powerful president in the history of America. And I'm gonna clean up this country!

Grob posted:

Interesting, I didn't know effect queues were supported by RJS!

Having said that it wouldn't solve the problem I had above as updating an element isn't an animation, but it would solve the initial question :)

Effect.Event is a skeleton effect that allows arbitrary functions to be treated as effects for the purpose of queueing.

Evil Trout
Nov 16, 2004

The evilest trout of them all

savetheclocktower posted:

Effect.Event is a skeleton effect that allows arbitrary functions to be treated as effects for the purpose of queueing.

Yes, but I was talking about RJS. It's not hard to trigger an arbitrary function call for a visual effect when writing your own Javascript, the issue is doing it from RJS. For example, you can say:

code:
render :update do |page|
  page.delay(3) do
   # something
  end
end
And I was saying I'm not aware of a way to do:
code:
render :update do |page|
  page.visual_effect :blind_down do
    #something
  end
end
Where something is not a page.visual_effect, for example, a replace_html or a toggle or something like that.

My goal is to avoid writing external javascript files for simple things like fades and updates :)

I've found this technique, which involves using the << operator to write your own first-class functions, but it seems a bit of a hack.

skidooer
Aug 6, 2001

Grob posted:

And I was saying I'm not aware of a way to do:
How about something like this?
code:
def visual_effect_with_callback_generation(name, id = nil, options = {})
  options.each do |name,value|
    options[name] = "function() { #{JavaScriptGenerator(@context, &value)} }" if value.is_a?(Proc)
  end

  visual_effect_without_callback_generation(name, id, options)
end
alias_method_chain :visual_effect, :callback_generation

page.visual_effect :blind_down, 'id', :afterFinish => lambda { |after|
  after.visual_effect :blind_up
  after.hide :element
}
It's untested, but you get the idea.

skidooer fucked around with this message at 04:53 on Dec 17, 2007

savetheclocktower
Sep 23, 2004

You wait and see, Mr. Caruthers. I will be president! I'll be the most powerful president in the history of America. And I'm gonna clean up this country!

Grob posted:

Yes, but I was talking about RJS. It's not hard to trigger an arbitrary function call for a visual effect when writing your own Javascript, the issue is doing it from RJS.

I'd put all that behavior into JavaScript, then call it via RJS.
code:
// JS:
Foo.bar = function() { /* ugly stuff goes here */ }

// RJS:
page.foo.bar()
You can even pass arguments if you need to.

All the simpler RJS statements can remain that way, but this is a good way to put really hairy logic into a black box.

As for this...

Grob posted:

My goal is to avoid writing external javascript files for simple things like fades and updates

RJS isn't a leakproof abstraction. It's really just a way to place Ajax logic in your controller, where it makes sense to live. If you try to write everything in pure RJS, never touching JavaScript at all, you'll just end up uglifying your controllers.

Hammertime
May 21, 2003
stop

savetheclocktower posted:

RJS isn't a leakproof abstraction. It's really just a way to place Ajax logic in your controller, where it makes sense to live. If you try to write everything in pure RJS, never touching JavaScript at all, you'll just end up uglifying your controllers.

And slowing your application. The escape method used in updating page content through rjs (as opposed to doing a prototype Ajax Update) is pretty slow.

Evil Trout
Nov 16, 2004

The evilest trout of them all

skidooer posted:

How about something like this?

This is exactly the kind of thing I want (and think RJS needs). I'll take a look later and see how it works, thanks!

savetheclocktower posted:

RJS isn't a leakproof abstraction. It's really just a way to place Ajax logic in your controller, where it makes sense to live. If you try to write everything in pure RJS, never touching JavaScript at all, you'll just end up uglifying your controllers.

Again, I'm aware you can call arbitrary Javascript from RJS. I don't want to write everything in RJS, but there are many cases where you just want to chain a couple of animations to an update.

Regarding the uglyfying of your controllers, anything more than a couple of lines of RJS goes in a .rjs file in my view directory.

Hop Pocket
Sep 23, 2003

Thanks for the help with the RJS. I used the delay / duration combo successfully. Will look more into the method chaining, but that's just a bit over my head at the moment.


vvvv word, thanks. That will come in very handy :cool:

Hop Pocket fucked around with this message at 04:07 on Dec 18, 2007

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Hop Pocket posted:

Thanks for the help with the RJS. I used the delay / duration combo successfully. Will look more into the method chaining, but that's just a bit over my head at the moment.

For some reason I went a whole year before noticing the very helpful empty application.js file in the javascripts directory. It's just sitting there ready to be used for things like this, I went ahead and kept creating extra js files or used inline javascript instead of capitalizing on the convenience of it.

So just a tip but if you haven't noticed it already, its there.

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
I suppose this is more of a linux question, but anyhow, I recently started running ubuntu on my laptop. Is there a way to run script/server in the background while I'm using the terminal? I'd like to be able to easily kill the process, too, but I'm not sure how to do that.

Wait till you guys see my next little project -- I'm kinda proud of it. It's for a friend, and it looks spectacular.

Trabisnikof
Dec 24, 2005

MrSaturn posted:

I suppose this is more of a linux question, but anyhow, I recently started running ubuntu on my laptop. Is there a way to run script/server in the background while I'm using the terminal? I'd like to be able to easily kill the process, too, but I'm not sure how to do that.

Wait till you guys see my next little project -- I'm kinda proud of it. It's for a friend, and it looks spectacular.

mongrel_rails start -d will start it in the background, then mongrel_rails stop will stop the server. Or mongrel_rails restart will reload it. This is of course with mongrel_rails, but that's cause its awesome.

skidooer
Aug 6, 2001

Trabisnikof posted:

mongrel_rails start -d will start it in the background, then mongrel_rails stop will stop the server. Or mongrel_rails restart will reload it. This is of course with mongrel_rails, but that's cause its awesome.
Or you can use the old fashioned & operator.
code:
$ script/server &
$ fg
^C
code:
$ mongrel_rails start &
$ fg
^C

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
While we're at it, is there a way to do that in windows, or at least to group all of my command prompt windows together (perhaps in tabs)? I run 3 rails apps on my desktop, and they can clutter up my startbar.

ericIII
Apr 8, 2001
I code for food.
script/server (at least mine from some random 1.2.x version of Rails) has a --daemon (-d) option

Xgkkp
Aug 20, 2004

by Lowtax
So I've used capistrano/mongrel to deploy and run, as the 'agile development with rails' book suggested. Does anyone know if:

a) This is the best way to deploy it
b) it's worth, and possible, preventing mongrel from accepting incoming connections outside of apache (i.e. nothing but localhost - I can access it at servername:8000 publically)
c) How I can easily get it to start at system boot - at the moment, the instances are started by capistrano directly, which obviously will die if the server goes down.

Evil Trout
Nov 16, 2004

The evilest trout of them all

Xgkkp posted:

So I've used capistrano/mongrel to deploy and run, as the 'agile development with rails' book suggested. Does anyone know if:

a) This is the best way to deploy it
b) it's worth, and possible, preventing mongrel from accepting incoming connections outside of apache (i.e. nothing but localhost - I can access it at servername:8000 publically)
c) How I can easily get it to start at system boot - at the moment, the instances are started by capistrano directly, which obviously will die if the server goes down.

There are many ways to deploy a Rails app and how you want to do it has a lot to do with the hardware you have and the traffic you expect.

a) I personally run a nginx web server in front of a pack of mongrels. It sounds like you're using Apache to do the same thing. I personally prefer Nginx because it's less bulky but the difference is minimal. Some benchmarks have shown that the best performance is on Apache2 with FastCGI Rails processes.

b) It is possible and worth it to configure what you're talking about. I personally recommend using a firewall on all public web servers. Basically you should configure your firewall so that it only accepts incoming data on the few ports you need (usually HTTP/HTTPS/SSH/DNS and maybe SMTP). If you do this local connections (from Apache to Mongrel) will work fine, but people from the outside world will only be able to tunnel through Apache. On Linux iptables is a good place to start looking.

c) Mongrel has a page about how to configure it to start on boot:
http://mongrel.rubyforge.org/docs/mongrel_cluster.html - mine is set up using the points in that document and it works great.

Xgkkp
Aug 20, 2004

by Lowtax
This is almost a purely apache question, but can I use mongrel and have it running on, instead of it's own subdomain (someapp.serveraddress), the site being like a subfolder serveraddress/someapp ? All the guides I have found are the former.

Hop Pocket
Sep 23, 2003

I am just starting to get into Rails caching, and so far so good. I have some expensive things in my layouts that I want to cache using fragment caching, but would probably want to expire just those fragments as the contents of the layout code changes. Ideally I'd be able to simply wipe out these fragment caches every time I deploy my app.

Is this best done using a Capistrano task?

EDIT: Nevermind. I realize now that if I store my cached files in the project directory under tmp/cache, that will automatically get reset by the svn export when Capistrano deploys the app. Awesome.

Hop Pocket fucked around with this message at 21:56 on Dec 20, 2007

bmoyles
Feb 15, 2002

United Neckbeard Foundation of America
Fun Shoe

Xgkkp posted:

This is almost a purely apache question, but can I use mongrel and have it running on, instead of it's own subdomain (someapp.serveraddress), the site being like a subfolder serveraddress/someapp ? All the guides I have found are the former.

absolutely. Are you using mod_proxy to pass traffic back to your mongrels?

Here's a config that works for apache 2.2:
edit: and should work for earlier apache versions
code:
    Alias /railsapp /path/to/rails/app/public
    <Directory /path/to/rails/app/public>
        RewriteEngine On
        RewriteBase /railsapp
        RewriteRule ^$ index.html [QSA]
        RewriteRule ^([^.]+)$ $1.html [QSA]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ [url]http://127.0.0.1:8000/[/url]$1 [QSA,P]
        ProxyPassReverse [url]http://127.0.0.1:8000[/url]
    </Directory>
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
Naturally, that last RewriteRule and ProxyPassReverse should be modified to match your mongrel config. That is the setup for a single mongrel. It's a little different if you have multiple mongrels and want to use something like mod_proxy_balancer to load balance.

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
I use a plugin that uses the old style pagination, which has apparently been deprecated now with 2.0's release: http://api.rubyonrails.com/classes/ActionController/Pagination.html

I can't seem to get classic_pagination to install using gems or the direct install command given on that page, so I want to update the plugin to use the new pagination.

How do I reference pagination in it's new package?
the old code looks like this
code:
        @pages = ::ActionController::Pagination::Paginator.new(self, total_number, page_size, page)

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

MrSaturn posted:

I use a plugin that uses the old style pagination, which has apparently been deprecated now with 2.0's release: http://api.rubyonrails.com/classes/ActionController/Pagination.html

I can't seem to get classic_pagination to install using gems or the direct install command given on that page, so I want to update the plugin to use the new pagination.

How do I reference pagination in it's new package?
the old code looks like this

Pagination should look the same as it did before with classic_pagination, like this.
code:
@person_pages, @people = paginate :people, :order => 'last_name, first_name'
New pagination, will_paginate should look more like this.
code:
@people = Person.paginate(:page => params[:page],
      :per_page => 10,
      :order => 'last_name, first_name')
Page and per_page are required.

http://nasir.wordpress.com/2007/10/31/pagination-in-ruby-on-rails-using-will_paginate-plugin/

SpaceNinja
Jul 24, 2002

by DocEvil
How do I install older versions of Rails? I'm just learning how to use Rails, and the book I bought doesn't cover anything about 2.0. Enough seems to be different that things aren't quite working the way I expect them to, and it's remarkably frustrating, because I remember when I had given this a shot in the past everything seemed to be fine.

This is with OS X, by the way, and I've so far just been downloading the source and then compiling and installing manually with the terminal.

Edit: Ah, got it. gem install rails -v 1.2.6

SpaceNinja fucked around with this message at 03:07 on Dec 23, 2007

HIERARCHY OF WEEDZ
Aug 1, 2005

I'm trying to use curl to get a better feel for this REST stuff, but any action I attempt raises an InvalidAuthenticityToken exception. I imagine I need to have some kind of session ID, but I don't know how I'd generate that from curl. Any ideas?

Adbot
ADBOT LOVES YOU

Pardot
Jul 25, 2001




MrSaturn posted:

classic_pagination

Instead of that, which was taken out for a reason, give this on a try will_paginate:
http://errtheblog.com/posts/47-i-will-paginate
http://errtheblog.com/posts/56-im-paginating-again

just do piston import svn co svn://errtheblog.com/svn/plugins/will_paginate vendor/plugins and try it out. If you don't like it then go back to classic. Piston, assuming that you're keeping your stuff in a svn repo.

edit: here's a screencast on it: http://railscasts.com/episodes/51

Pardot fucked around with this message at 07:49 on Dec 24, 2007

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