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
Hop Pocket
Sep 23, 2003

What is the rails equivalent of a Quartz scheduler? I want something that will execute periodic jobs on the development/production servers. I'd prefer to stay outside of the OS level cron and inside the application if possible in case our production server ends up being hosted on Windows.

Adbot
ADBOT LOVES YOU

Evil Trout
Nov 16, 2004

The evilest trout of them all

Hop Pocket posted:

What is the rails equivalent of a Quartz scheduler? I want something that will execute periodic jobs on the development/production servers. I'd prefer to stay outside of the OS level cron and inside the application if possible in case our production server ends up being hosted on Windows.

I looked for something like this months ago and couldn't come up with anything. So my site uses cron for all jobs, using the "script/runner"

bmoyles
Feb 15, 2002

United Neckbeard Foundation of America
Fun Shoe
You won't find a Quartz-alike until rails runs in a threaded app server. Rails apps are triggered by events like a user hitting a page. There's no constant thread running that can be used to do stuff like run jobs.

skidooer
Aug 6, 2001

Hop Pocket posted:

What is the rails equivalent of a Quartz scheduler? I want something that will execute periodic jobs on the development/production servers.
Backgroundrb should fit the bill.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

skidooer posted:

Backgroundrb should fit the bill.

Looks like they're dropping support for Windows, though.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I would understand that sometimes you might have to, but if you don't need to would you really try to host a Rails application on a Windows server?

Hop Pocket
Sep 23, 2003

Thanks for the responses. I was really confused about this but think I understand it a bit better now. At any rate, I don't see any reason why I would be forced to host on a windows machine. I'm coming from five years of Java / J2EE development, and am used to being very scared of deploying a solution that is OS dependent.

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
maybe some of you rails gurus can help me with this. I'm running instant rails on a windows host machine, and I recently bought a domain name that i want to use to point to one of my rails apps. It's running on port 3002 locally (http://localhost:3002) and I just can't figure out how to reroute that to go to the default port (80 I suppose) that my domain will be referencing.

I have the domain registered through mydomain, and I can get to the application if I go to the domain with a port extension on it (http://domain.com:3002) but http://domain.com doesn't work.

I have a feeling that my ISP may block port 80 incoming, but I'm not sure. I subscribe to comcast cable, if that helps.

What config do I have to edit to make this all work?

Argue
Sep 29, 2005

I represent the Philippines
Manage Rails Applications -> Configure startup mode

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Try port routing in your router settings, set up port 80 to point to port 3002 on your local computer. This will only work if your ISP doesn't block incoming connections to port 80.

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
Is either one of acts_as_searchable or acts_as_ferret inherently better than the other?

Hop Pocket
Sep 23, 2003

Sometimes after my laptop sleeps and then wakes up, my local RoR app running at :3000 will "break". That is, I will get a "broken pipe" error for any controller action.

code:
Errno::EPIPE (Broken pipe):
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/mysql.rb:1042:in `flush'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/mysql.rb:1042:in `write'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/mysql.rb:462:in `write'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/mysql.rb:436:in `command'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/mysql.rb:307:in `stat'
    ......
Is there a way to fix this without simply restarting Mongrel?

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
So I've made this odd little blog type page for myself, just to experiment with some techniques I haven't yet used. I'm trying to use the scriptaculous stuff built into rails to show/hide the comments on a given post. Right now, all the comments for a post are in a

code:
<div id="comments_11">
</div>
where 11 is the id of the post. in the view file for my blog, I have

code:
<%= link_to 'comments', :action => :showcomments, :id => this.id %>
which points to a .rjs file called showcomments.rjs in that view folder.
The rjs file looks like this:
code:
page[:comments_11].visual_effect :toggle_blind
first off, I can't quite figure out what I need to do to make that "11" in the .rjs dynamic. Secondly, when I click on the link that's made in the blog, I just get forwarded to
/front/showcomments/11

and it says
code:
try {
$("comments_11").visualEffect("toggle_blind");
} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('$(\"comments_11\").visualEffect(\"toggle_blind\");'); throw e }
what did I gently caress up? I feel like it's not referencing the right object.

if you want to see the page, it's temporarily located at http://jivewise.livenode.com:3002/ (until I can get the port forwarding problems I talked about above sorted out)

Hop Pocket
Sep 23, 2003

MrSaturn posted:

code:
<%= link_to 'comments', :action => :showcomments, :id => this.id %>
which points to a .rjs file called showcomments.rjs in that view folder.
The rjs file looks like this:
code:
page[:comments_11].visual_effect :toggle_blind
first off, I can't quite figure out what I need to do to make that "11" in the .rjs dynamic. Secondly, when I click on the link that's made in the blog, I just get forwarded to
/front/showcomments/11


Funny, I was just working on the very same thing today. Really. I believe that you need to use a link_to_remote to force a JS request. That way your RJS template will be evaluated by the browser JS engine on return. The fact that you're using link_to means that it's generating an A tag that will force a page reload, which is not what you're wanting, I think.

Secondly, in your RJS template, use an instance member that your controller makes available to control the id.

code:
def show_comments
  @file = File.find(params[:id])
  ....
end
Then, in your RJS:

code:
div_id = "comments_#{@file.id}"
page.replace_html div_id, :partial=>'your_partial_goes_here_to_render_the_comments'
page[div_id].visual_effect :toggle_blind
I've assumed that you're wanting to do some content insertion, which is why I used the replace_html. Sorry if that's not the case.

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...

Hop Pocket posted:

Funny, I was just working on the very same thing today. Really. I believe that you need to use a link_to_remote to force a JS request. That way your RJS template will be evaluated by the browser JS engine on return. The fact that you're using link_to means that it's generating an A tag that will force a page reload, which is not what you're wanting, I think.

Secondly, in your RJS template, use an instance member that your controller makes available to control the id.

code:
def show_comments
  @file = File.find(params[:id])
  ....
end
Then, in your RJS:

code:
div_id = "comments_#{@file.id}"
page.replace_html div_id, :partial=>'your_partial_goes_here_to_render_the_comments'
page[div_id].visual_effect :toggle_blind
I've assumed that you're wanting to do some content insertion, which is why I used the replace_html. Sorry if that's not the case.

I'm getting closer... if I keep the comments_11 in the .rjs, I get these 2 errors when I click my link:

code:
RJS error:

TypeError: Effect[klass] is not a constructor

and then 

$("comments_11").visualEffect("toggle_blind");
if I modify the comments controller like you showed, nothing happens at all.

Hop Pocket
Sep 23, 2003

MrSaturn posted:

I'm getting closer... if I keep the comments_11 in the .rjs, I get these 2 errors when I click my link:

code:
RJS error:

TypeError: Effect[klass] is not a constructor

and then 

$("comments_11").visualEffect("toggle_blind");
if I modify the comments controller like you showed, nothing happens at all.

It sounds like you may not have the javascript libraries loaded. In your <HEAD> tag in your layout or template, make sure you have:

code:
<%= javascript_include_tag :defaults %> 
That will load the scriptaculous (and other) libraries on which the RJS-generated code is dependent.

With regards to the comments controller, is your RJS template getting invoked?

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...

Hop Pocket posted:

It sounds like you may not have the javascript libraries loaded. In your <HEAD> tag in your layout or template, make sure you have:

code:
<%= javascript_include_tag :defaults %> 
That will load the scriptaculous (and other) libraries on which the RJS-generated code is dependent.

With regards to the comments controller, is your RJS template getting invoked?

I've definitely got javascript loaded up. And i'm pretty sure the rjs template is invoked directly from the link_to_remote that I put in:

code:
<%= link_to_remote 'comments', :url => '/front/showcomments/' + this.id.to_s %>
should I be putting the controller logic in the comments controller, or the frontpage controller?

Pardot
Jul 25, 2001




Also keep in mind that even when you get this working, it's really not the best way of going about it. Every time they click the show/hide button, they are being sent to the server to get the 1 line of javascript to do the show or hide. This should be done as an inline js function, allong the lines of:
code:
link_to_function "comments" { |page| page[:comments_11].visual_effect :toggle_blind }
Edit: Only hit the server when you have to go and get (a lot of) new data, or update things, as it's relatively expensive to do. For something like blog comments, all of them should be sent with the blog post, or at least the first page of 40 or so.

Pardot fucked around with this message at 21:25 on Nov 18, 2007

Hop Pocket
Sep 23, 2003

MrSaturn posted:

I've definitely got javascript loaded up. And i'm pretty sure the rjs template is invoked directly from the link_to_remote that I put in:

code:
<%= link_to_remote 'comments', :url => '/front/showcomments/' + this.id.to_s %>
should I be putting the controller logic in the comments controller, or the frontpage controller?

To be honest, I'm not sure. It probably doesn't matter a whole lot, as long as you're sure that the controller is getting invoked. You can verify this by looking at the rails console, which will output each controller action that is executed.

I would probably recommend as well that you structure your links like this:

code:
<%= link_to_remote 'comments', :url=>{ :controller=>:comments, :action=>:showcomments, :id=>@file } %>
Assuming that you have a controller called "comments", and an action within that controller called "showcomments" and that you have an instance member available called @file.

Anal Wink posted:

Edit: Only hit the server when you have to go and get (a lot of) new data, or update things, as it's relatively expensive to do. For something like blog comments, all of them should be sent with the blog post, or at least the first page of 40 or so.

Yes, this is good advice. If you've already got the data that you need on the page and you wish to work solely within that realm, no need to hit the server. I was under the assumption that you were loading the comments from the db in your 'showcomments' action.

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...

Hop Pocket posted:


Yes, this is good advice. If you've already got the data that you need on the page and you wish to work solely within that realm, no need to hit the server. I was under the assumption that you were loading the comments from the db in your 'showcomments' action.

yeah, I wasn't. I'm trying to do it inline now. I'm going to use Element.toggle for now, until I can figure everything else out. Then I'll get fancy with scriptaculous :smith:

Hop Pocket
Sep 23, 2003

MrSaturn posted:

yeah, I wasn't. I'm trying to do it inline now. I'm going to use Element.toggle for now, until I can figure everything else out. Then I'll get fancy with scriptaculous :smith:

If you've got the $25 bucks to spend, I'd really recommend the 'Agile Development With Rails' PDF available here. It helped me out with a lot of rails stuff. May help you, depending on where you are.

vvv :cool:

Hop Pocket fucked around with this message at 22:34 on Nov 18, 2007

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...

Hop Pocket posted:

If you've got the $25 bucks to spend, I'd really recommend the 'Agile Development With Rails' PDF available here. It helped me out with a lot of rails stuff. May help you, depending on where you are.

it's sitting right next to me on my desk. I use it all the time, the only thing is I'm using the hobo plugin for my apps, which tends to add an element of complexity to my understanding the book. Great book, though, hands down.

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
Ooooo got it working. Snazzy, eh?
http://jivewise.livenode.com:3002/


...now to let people add comments via ajax so they don't ever leave the frontpage...

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
Embarrassingly retarded question... I can't believe I can't figure out the answer to this on my own. Imagine I've got something like the following:

code:
@posts = Post.find(:all)
Which then gets passed to the view, yadda yadda yadda, this is all basic stuff. But what if @posts is empty (in this case there's no data) and I want to alter the view accordingly. I thought it would be a matter of doing something like the following:

code:
<% if @posts.nil? %>
  <p>No posts!</p>
<% else %>
  # Loop through @posts
<% end %>
But apparently not. Oh god, how do I do this? Put me out of my misery.

Evil Trout
Nov 16, 2004

The evilest trout of them all

SeventySeven posted:

Embarrassingly retarded question... I can't believe I can't figure out the answer to this on my own. Imagine I've got something like the following:

code:
@posts = Post.find(:all)
Which then gets passed to the view, yadda yadda yadda, this is all basic stuff. But what if @posts is empty (in this case there's no data) and I want to alter the view accordingly. I thought it would be a matter of doing something like the following:

code:
<% if @posts.nil? %>
  <p>No posts!</p>
<% else %>
  # Loop through @posts
<% end %>
But apparently not. Oh god, how do I do this? Put me out of my misery.

code:
<% if @posts.size == 0 %>
  <p>No posts!</p>
<% else %>
  display posts
<% end %>

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
:ssj: Why didn't I think of that? I tried @posts.length and @posts.count.

Thanks.

Evil Trout
Nov 16, 2004

The evilest trout of them all

SeventySeven posted:

:ssj: Why didn't I think of that? I tried @posts.length and @posts.count.

Thanks.

Actually @posts.length should work too. @posts.size is equivalent, so I'm not sure why that failed!

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.

Grob posted:

Actually @posts.length should work too. @posts.size is equivalent, so I'm not sure why that failed!

Hmm, so it does, guess I forgot what I tried. It all seems so obvious now.

hmm yes
Dec 2, 2000
College Slice
I've always used

if @posts.nil? || if @posts.blank?

burntoutjoy
Jul 21, 2003

Lemons Through the Time Tunnel!!
@posts.empty?

:)

skidooer
Aug 6, 2001

atastypie posted:

I've always used

if @posts.nil? || if @posts.blank?
Your nil? check is redundant considering that blank? will return false if @posts is nil.

The Journey Fraternity
Nov 25, 2003



I found this on the ground!

burntoutjoy posted:

@posts.empty?

:)

This is the best one right here. Short, concrete, and simple.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

skidooer posted:

Your nil? check is redundant considering that blank? will return false if @posts is nil.

Is "blank?" what I am looking for?

I've always wanted something similar to @posts.title.empty_or_nil? In case the value being returned in the database is blank instead of nil for whatever reason, as nil.empty? would return an error.

Or.. does it? I'm getting confused.

I seem to just remember creating my own empty_or_nil? method at some point before to handle it.

Nolgthorn fucked around with this message at 06:50 on Nov 20, 2007

skidooer
Aug 6, 2001

Nolgthorn posted:

Is "blank?" what I am looking for?

I've always wanted something similar to @posts.title.empty_or_nil? In case the value being returned in the database is blank instead of nil for whatever reason, as nil.empty? would return an error.

Or.. does it? I'm getting confused.
Yes, object.blank? is equivalent to object.nil? || object.empty? Note that it's provided by ActiveSupport should you find yourself trying to use it outside of Rails.

zigb
Mar 21, 2007
I'm a PHP coder who is nearing completion on my first RoR project. The project is to port someone's large spaghetti bowl of a MsAccess app to MySQL/RoR. I (alas!) can't change the database layout, including table and column names, due to design constraints beyond my control. Here's what I liked and disliked about the RoR experience.

The Good:
- Database migrations. These are truly lovely. At any time I can drop the entire db structure, then recreate it and copy the live data over from SQL Server. Or just downgrade the data migration and then run it again. This allows me to test against a copy of the live data and then reset my copy once I feel I've corrupted the data too much.

- Enforced (or at least strongly encouraged) MVC design pattern. Sure, it's nice.. that said I was using MVC previously in both CakePHP and later my own simple custom framework.

- Helpers are cool. I'd rather type <%= text_field :object, :accessor, :etc %> than <input type="text" ... />, and they become especially cool when I need to read the input data in a controller. form_for is bitchen.

The Bad:
- Documentation. For gently caress's sake people, at least pretend like you're trying. I'd say around 90% of the helpers and controller methods I found on api.rubyonrails.org had "options = {}" in the signature without any further information. In the entire page. For as many people here hate PHP, some of you must have tried it. Remember the documentation? It has a search box, for one. It also tells you exactly which PHP versions the function in question works in, and any differences between those versions. The PHP docs are also available in something like 22 different languages.

- Server restarts. Our dev server is also, unfortunately, a production server for different apps in other languages. (don't blame me, I didn't do it :(). Under Apache/FastCGI/RoR there are too many times we need to restart Apache. Changed something in environment.rb? Restart Apache. Added/Edited something in the /lib path? Restart Apache. This makes any sort of iterative development of libs/mixins a huge pain in the rear end. Particularly since I have to go beg the sysadmin to restart Apache.. How is this even considered acceptable? Is it just assumed that one server will run only one RoR app? There are live apps being taken offline every time I need to update a library.

- SQL Logging. Didn't work, even when I triple checked that the /tmp and /log dirs had proper permissions and that logging wasn't disabled in the environment files. I even tried chmodding /tmp and /log to 777, still no logs. There were a couple situations where knowing what sort of SQL ActiveRecord was generating would've saved us some serious headaches.

The Gotchas:
- 'type' db field. The original MSSQL db had a 'type' field in one of the tables. It can be used as a regular field, but only after putting a dummy value in the model for inheritance_column, then accessing the member as object[:type] instead of object.type. This of course breaks all attributes= and object.attributes calls, requiring an extra line after them that explicitly sets object[:type].

- You still write SQL, for any sort of advanced find / sort. Not that I mind writing SQL, but I prefer to write it in one large understandable chunk instead of splitting it up into mini-clauses, like :conditions => "[some sql]", :order => "[some sql]", etc. Most find queries that required a JOIN or two had to be written using find_by_sql. Again, I like sql, but I feel like I'm cheating every time I use it in Rails.

- Controller initialize function. It causes "Internal Server Error" when I put simple logic in there. Example (this kills rails): "if null != params[:a_param]; end". Same thing when I put the logic in question into a method and call it from initialize. No problems when I call that same method from one of the actions instead.

- Different expectations for overriding ActionController::initialize and ActiveRecord::initialize. Many working code examples override initialize in a controller without calling super(). To be sure this was safe, I even looked at the code for ActionController::initialize which is an empty function. Later, assuming that this was a Rails convention (remember "convention over configuration"?), I overrode a model's initialize method without calling super. Hilarity ensued as I tried to track down why an object created in one line had none of its members in the next, even though it wasn't nil.

In conclusion
Rails didn't work for me this time around. Once I've finished this project I'll gladly put Rails down for a time and maybe try again once it's matured some. Perhaps it's just that the project required too much custom tweaking, I'm not sure. I came up against ActiveRecord's limitations several times, along with some of the more esoteric Rails gotchas. I've only listed a few here, but I'd estimate that 15 - 20 minutes of every hour were spent looking for help when Rails' "magic" turned evil, or looking for documentation on helpers. In most cases I'd find the answer on somebody's blog, usually 3 pages into a google result set, after trying in vain to find the relevant info in RoR's documentation.

While the above issues were all annoyances, the need to restart Apache after making code, not configuration, changes is the kicker. In contrast, we have a PHP application that's been running for three years solid without any downtime except for electrical problems/server room maintenance. We make changes to the codebase fairly regularly without ever requiring an Apache restart.

For my work I'm going to continue using PHP, most likely with the Zend Framework. I'm also going to check out Zope/Plone which is supposed to combine a built-in CMS with some new novel way of doing ORM. I feel Rails still has a way to go before it can offer more to your average developer than "Create a blog in x minutes".

burntoutjoy
Jul 21, 2003

Lemons Through the Time Tunnel!!

Nolgthorn posted:

Is "blank?" what I am looking for?

I've always wanted something similar to @posts.title.empty_or_nil? In case the value being returned in the database is blank instead of nil for whatever reason, as nil.empty? would return an error.

Or.. does it? I'm getting confused.

I seem to just remember creating my own empty_or_nil? method at some point before to handle it.

In the original case empty? would be fine as find(:all) never returns nil.

wunderbread384
Jun 24, 2004
America's favorite bread

zigb posted:

The Bad:
- Server restarts. Our dev server is also, unfortunately, a production server for different apps in other languages. (don't blame me, I didn't do it :(). Under Apache/FastCGI/RoR there are too many times we need to restart Apache. Changed something in environment.rb? Restart Apache. Added/Edited something in the /lib path? Restart Apache. This makes any sort of iterative development of libs/mixins a huge pain in the rear end. Particularly since I have to go beg the sysadmin to restart Apache.. How is this even considered acceptable? Is it just assumed that one server will run only one RoR app? There are live apps being taken offline every time I need to update a library.

Maybe I'm missing something, but why are you running FastCGI for your development server? If nothing else, it's why you were having to reload after changing code in your lib directory. I mean, the whole point of FastCGI is that it doesn't have to reload libraries for every request.

Pardot
Jul 25, 2001




zigb posted:

Apache/FastCGI/RoR

Is there a reason you're not using mongrel?

Evil Trout
Nov 16, 2004

The evilest trout of them all

zigb posted:

- You still write SQL, for any sort of advanced find / sort. Not that I mind writing SQL, but I prefer to write it in one large understandable chunk instead of splitting it up into mini-clauses, like :conditions => "[some sql]", :order => "[some sql]", etc. Most find queries that required a JOIN or two had to be written using find_by_sql. Again, I like sql, but I feel like I'm cheating every time I use it in Rails.

This puzzles me. I just deployed an online RPG game using rails with over 120 models, and I'd say I had to write manual SQL less than 1% of the time.

Especially the part where you say a join or two -- what kind of joins are you doing that aren't handled elegantly by ActiveRecord?

Adbot
ADBOT LOVES YOU

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

zigb posted:

- Server restarts. Our dev server is also, unfortunately, a production server for different apps in other languages. (don't blame me, I didn't do it :(). Under Apache/FastCGI/RoR there are too many times we need to restart Apache. Changed something in environment.rb? Restart Apache. Added/Edited something in the /lib path? Restart Apache. This makes any sort of iterative development of libs/mixins a huge pain in the rear end. Particularly since I have to go beg the sysadmin to restart Apache.. How is this even considered acceptable? Is it just assumed that one server will run only one RoR app? There are live apps being taken offline every time I need to update a library.

It's been a long time since I used Rails, but doesn't it come with a simple standalone web server you can use for testing? ISTR typing "rails test <appname>" or something starting my app listening on port 8080.

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