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

RonaldMcDonald posted:

In my opinion you can see a lot about languages from how they solve simple problems. So, for :science: how would the following PHP code look in RoR?

php:
<?
$result = mysql_query("select * from people order by lastname asc");
if (!$result)
    throw new Exception(mysql_error());

echo '<table>';
while ($row = mysql_fetch_array($result))
{
    echo '<tr>';
    echo '<td>', $row['lastname'], '</td>';
    echo '<td>', $row['firstname'], '</td>';
    echo '<td>', $row['age'], '</td>';
    echo '</tr>';
}
echo '</table>';
?>

You could do it like this but you're not supposed to:
code:
<% @people = Person.find(:all, :order => "lastname ASC") %>
<table>
<%= @people.collect {|i| "<tr><td>#{i.lastname}</td><td>#{i.firstname}</td><td>#{i.age}</td></tr>"} %>
</table>
If you did you would probably go to Ruby hell, especially if you showed anyone and they thought it was a good idea.

Adbot
ADBOT LOVES YOU

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I have a pretty serious question regarding rails log files in production. Every time a page is visited in your rails application there is a minimum of about 6 lines of information written about it to the log.

Some plugins such as better_nested_set which is pretty drat well near necessary for some applications, there is a command that is going to be depreciated in an upcoming version of rails so you get about 30 or 40 (or however many rows of information are in your database) lines of text written to your log file, each one with a long description telling you about it.

On a traffic heavy web site this log file will eventually get really big right? Isn't that bad? Regardless I want to turn it off.


Thanks. vvvv Related to this is there a good place to figure out what environment.rb is not used for?

Nolgthorn fucked around with this message at 20:28 on Aug 10, 2007

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

scr0llwheel posted:

So I'm thinking of starting a project with RoR but have one question: Is there a suitable way to do user registration, authentication, etc? Granted, I haven't looked into it very much, but all authentication stuff seems to be either the entire site or nothing. What I'd specifically like to do is to protect an admin control panel along with admin-only elements/controls on an otherwise publicly viewable page.

Is this built into RoR and I just missed it? Are there any gems available to do this? How hard is this to implement?

If all you need is one admin user then you don't need restful_authentication, this is much simpler and should fulfill your need:

Controller:
code:
  def login
    if request.post?
      if params[:login] == "admin" and params[:password] == "admin_pw"
        session[:logged_in] = true
        redirect_to admin_page_url
      end
    end
  end
  
  def logout
    session[:logged_in] = nil
    redirect_to :action => "login"
  end
ApplicationController:
code:
  def logged_in?
     return session[:logged_in] ? true : false
  end
  helper_method :logged_in?
Then use "if logged_in?" anywhere that you want.

Nolgthorn fucked around with this message at 03:13 on Aug 29, 2007

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

smackfu posted:

Rails makes me cry when I look at the SQL calls. I mean, it's very easy to get a working application, but then you wonder why it's slow, and it's because it's doing 100 db calls for a 100 item list. Oy.

You're right it's not perfect but you also have to use it properly.

@authors = Authors.find(:all, :include => ["books", {"screenplays" => "movie"}])

If the application is making 100 db calls for a 100 item list then you have forgotten to use eager loading. Now you can loop through, request the author.books or whatever and it won't have to get that information from the database for each one.

Edit: Sorry, not intended to sound mean.

Nolgthorn fucked around with this message at 07:15 on Aug 30, 2007

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
It seems Active Record will not save grandchildren and their parent at the same time, am I doing something wrong or is it something to do with my polymorphic association?

code:
#Section has_one SideColumn
#SideColumn has_one ColumnImage as "attachment" (polymorphic)

    @side_column = SideColumn.new(params[:side_column])
    return unless request.post?
    @section.side_column = @side_column
    unless params[:column_image].empty?
      @section.side_column.column_image = ColumnImage.new(params[:column_image])
    end
    @section.save

#=> SideColumn gets saved but ColumnImage does not.
I have verified params[:column_image] is not empty, when I comment out the conditional I still get the same result.


It's not really relevant but here is a pastie of my models if someone needs to see.
http://pastie.caboo.se/116397

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
In this example SideColumn would not have been created yet so it would undoubtedly throw an error since ColumnImage would not have a row in the database to reference.

I would have to save ColumnImage separately afterwards, but I'm trying to get it all into one nice neat transaction.

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?

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.

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

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
code:
sql = "SELECT p.* FROM payment AS p \
	LEFT JOIN school AS s ON p.schoolID = s.schoolID \
	LEFT JOIN cost AS c ON p.costID = c.costID \
	LEFT JOIN databaseInformation AS d on c.databaseID = d.databaseID
	WHERE s.schoolName LIKE '%school redacted%' && library NOT LIKE '%library also redacted%' \
	&& c.subscriptionStart >= '" + @dateStart.to_formatted_s(:db) + "' \
	&& c.subscriptionEnd <= '" + @dateEnd.to_formatted_s(:db) + "' \
	ORDER BY s.schoolName, s.library, d.databaseName"
					
@payments = Payment.find_by_sql(sql)
I don't know what hashappened, don't use camelCase, make sure you use properly named foreign keys, primary keys and this will work.

This won't work properly otherwise without a little bit of extra declarations in your model and such specifying the ruby-way ness. You may have to fix the pluralization, to make tables the ruby way have them all named in the pluralized sense.

Then to get information from it, pluralization starts to depends on what kind of relationship the tables have with one another. This should approximately begin to start to get at what you are going for. I think it might be a needlessly complex task, I don't know what the function of your application is so I can't tell.
code:
@payments = Payment.find(:all,
    :include => ["school", {"cost" => "database_information"}],
    :conditions => ["schools.name LIKE '%?%'
        AND schools.library NOT LIKE '%?%'
        AND costs.subscription_start >= ?
        AND costs.subscription_end <= ?",
      "school redacted", "library also redacted",
      @date_start.to_formatted_s(:db), @date_end.to_formatted_s(:db)],
    :order => "schools.name, schools.library, database_information.name")
A find method this large you are going to want to move it into your Payment model... as a start.

Good luck!

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

MonkeyMaker posted:

Anyone know of a quick/easy way to provide 'validates_X'-style validation on non-model checks? Like if a .find comes up blank, show an error/alert, instead of having to code that exception explicitly every time?

If you use .find_by_id in place of .find, then if that .find_by_id comes up blank it will return nil instead of an error.
code:
unless @group = Group.find_by_id(params[:id])
  redirect_to home_url
  return false
end
# Do something with @group here.
I use the above code all the time because this, below, would page the database twice.
code:
unless Group.exists?(params[:id])
  redirect_to home_url
  return false
end
@group = Group.find(params[:id])
# Do something with @group here.

Nolgthorn fucked around with this message at 03:50 on Dec 6, 2007

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I'm trying to write sort of a short-and-sweet authentication permissions system. As it is right now, I know how I think I want it to work but I'm having trouble making it escape the controller action that was running if validation fails.

Controller in some action:
code:
      if belongs_to_current_user?(@article)
        # User must have permission to edit their own article
        permission_required("article", "edit")
      else
        # User must have permission to edit other's articles
        permission_required("article", "edit-a")
      end
Application controller:
code:
  # Denies access to unauthorized users.
  def permission_required(cont, code)
    unless permission?(cont, code)
      flash[:warning] = "You don't have the permission required for access to this function"
      redirect_to home_url
      return false
    end
  end
The "return false" I have there, I want it cancel processing from the action in my controller but it only cancels processing from the rest of the permission_required method.

I'm at a loss as to how to put code safely after calling permission_required in my controller, without worrying about it getting executed anyway after the user is redirected.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

shopvac4christ posted:

This blog post

This looks neat. I like this part, it may help with my problem.

quote:

Action Pack: Exception handling

Lots of common exceptions would do better to be rescued at a shared level rather than per action. This has always been possible by overwriting rescue_action_in_public, but then you had to roll out your own case statement and call super. Bah. So now we have a class level macro called rescue_from, which you can use to declaratively point certain exceptions to a given action. Example:


class PostsController < ApplicationController
rescue_from User::NotAuthorized, :with => :deny_access

protected
def deny_access
...
end
end

I like to keep things as tidy as possible.

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.

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/

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

bmoyles posted:

Someone pissed in Zed Shaw's cheerios
http://www.zedshaw.com/rants/rails_is_a_ghetto.html
Fun read :)

"There’s no work for a smart man in a town full of stupid."

This was my favorite part, I find it very funny. As well I got some good tips on new frameworks out of reading that, one or two frameworks that I want to use.

Thank you.


Edit: A lot of drama was in that read GEEEZ.

Nolgthorn fucked around with this message at 11:23 on Jan 4, 2008

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Help!

I have a technical interview coming up for employment in a salary based role using Ruby on Rails. Up until now all of my professional work with Rails has been under contract and I've done or learned about only what I wanted to know.

I'm really nervous because I realize that -first of all- I want the job, but that I don't know dilly about what is expected when working with other programmers.

That's not true, I learned some about Microsoft SVN while I was getting my MCAD in school, but MCADs don't help in Rails!

Should I know about SVN, Mongrel, page caching and stuff because I don't know about those things. I've always deployed by hand to whatever was available on the server, I've created about 20 commercial web sites in the last year.

Is there anything else I should quickly learn about in the next day or so that wouldn't have been covered in all the blogs out there?

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

SeventySeven posted:

I know Hobo is mentioned in the first few posts but has anyone done anything with it since? I thought I'd have a go at rewriting an existing Rails app with it to add some functionality (users and permissions) and to fix some problems with the old app. The problem I'm facing now is there's, as far as I can see, no documentation whatsoever for recent iterations of DRYML. Does anyone know if there is any reference at all?

I am eagerly anticipating using datamapper in the future when it becomes compatible with Windows, so I hope that it is still under heavy development. My first impressions of merb about a month ago was that it was being heavily documented.

Are these two things not the case anymore?


Edit: Also I'm still waiting to hear back from the job I want, from earlier up on this page. I'll let you guys know how it goes, here's crossing my fingers!

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Nolgthorn posted:

Edit: Also I'm still waiting to hear back from the job I want, from earlier up on this page. I'll let you guys know how it goes, here's crossing my fingers!

I got the job, one question came up in the final interview of interest. If technology was today's, but my career was five years from now, then what do I see myself doing?

Sort of a slightly different take on the "Five years from now?" question, supposedly to eliminate some of the "I'd be using space programming!" answers, which was my first instinct.

Woo hoo!

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I have a $5/month account at https://www.railsplayground.com and host 4 small applications on it. What is all this dedicated talk, shared hosting is sufficient for a blog, band website, small business website and extraneous test or staging application.

geez

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Lets say I have about 20 tables that include more or less each a set of options for 20 different select boxes. These will change rarely, I have set up all the functionality required to display these select boxes and show the user's selected options somewhere all over a page someplace.

What is the best way to ensure there aren't 20 hits to the database on every edit request and a further 20 hits to the database on every page view where these results are displayed?

I can use page caching where the results are displayed but I am a bit dumbfounded by the idea of caching the select boxes that allow the users to change these settings as they need to be pre-populated with the values the user has selected.

Is the best way to just page cache on the edit page as well? Because the chances are that any time a user visits the edit page, they will be changing something that will clear the cache anyways.

Nolgthorn fucked around with this message at 09:39 on Jul 18, 2008

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I am about to try and create my first plugin out of a CMS I built from scratch (with the help only of awesome awesome attachment_fu) but I've never created a plugin before and am having troubles finding a full walkthrough of the process and possibilities.

The plugin will involve view helpers, controller methods and models. The CMS runs on a behind the scenes Admin interface with a different layout and a password. The front end needs to be highly configurable and the controller methods not so much so, this will be more or less an internal plugin that we are capable of making modifications to if need be.

My question is where do I go to learn about the best ways of doing this that is not out of date?

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Making plugins is hard, would something this complex be better as a generator? Would that be any easier or more useful than having it as a plugin?

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Pardot posted:

Having plugins that have views and stuff is hard in rails. There is something called plugin engines that do that, but it got some hate in 2006 from dhh, and I'm not sure what the current state of the project is.
Thanks for this suggestion.

I went to the website and it's nothing but the poor developers overly defending the project like crazy for pages and pages and pages, geez. I'm so taken back now I'm not even sure what to do to start using the drat thing. All of the tutorials that are being linked to seem to be down, it looks like a nice project, being able to put a generator into a plugin sounds just the ticket.

I'll try and investigate further. I wish that the developers of Rails engines spent more time writing documentation than they did actually listening to all this criticism, sometimes the Rails community baffles me.

Nolgthorn fucked around with this message at 02:41 on Jul 23, 2008

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

j4on posted:

Let's say you work in a "fast and dirty" coding environment (news website) where most projects go from design to publish in under a week, sometimes only one day, and usually involve only one coder. Maintenance on old code is rarely needed, but deadlines absolutely can not be missed: if breaking the MVC paradigm will save one hour, by God break it. For these kind of small data-driven "mini-sites" is RoR still better than PHP? Or should I be lookng to learn something else entirely?

I would recommend spending any downtime you have building something which can be reused to build what you most usually do instantly. That or switching to Django, if you can manage Django it was actually built for news websites by a large news website something or other and does everything you want fast.

Once you've defined what your database looks like all you need to do is build a front end, the administration portion is already done, fyi but I find it hard.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Re; Rails Engines
AGHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
*falls over*
*twitches*

Thanks Rails community for doing everything in your power to prevent Rails Engines, which is exactly what I need from having been updated in a year so that it no longer works. That's great how something that obviously had a lot of time and effort put into it got flogged so badly that the developers finally said 'gently caress this' and gave up on it.

Rails is now much better for not having this plugin available to those who would have wanted it in the future.

I'll surely not be considering contributing a lot of my time and effort into a community if there is a risk my work will be responded to as if it were a youtube video.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I've tried all the versions... maybe I'm doing something wrong.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

luminalflux posted:

Yes, I should probably just let my database be a stupid object store, but a lot of habits (foreign keys, naming primary keys to make joins easier) are hard to shake.

Really I found that easy, as soon as I didn't have to touch the database anymore I simply didn't. The added benefit of never having to bother doing anything other than change the data store any time I wish was a great benefit as well.

Edit: Also the ease of using sqlite3, which is my favorite data store.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
http://weblog.rubyonrails.org/2008/8/23/dos-vulnerabilities-in-rexml

quote:

The ruby-security team have published an advisory about a DoS bug affecting REXML users. Almost all rails applications will be affected by this vulnerability and you’re strongly advised to take the mitigating steps recommended in the advisory. If you’re not sure whether your application could be affected, you should upgrade.

The announcement contains details describing the monkeypatch solution, but to summarise:
Versions 1.2.6 and earlier

1. Copy the fix file into RAILS_ROOT/lib
2. Require the file from environment.rb require ‘rexml-expansion-fix’

Versions 2.0.0 and later

Copy the fix file into RAILS_ROOT/config/initializers, it will be required automatically.

This fix is also available as a gem, to install it run:

gem install rexml-expansion-fix

Then add require ‘rexml-expansion-fix’ to your environment.rb file. The manual fix and the gem are identical, if you have applied one you do not need to apply the other.

I also got a message from engineyard urging me to fix my installation.

quote:

Security researchers have uncovered a denial of service vulnerability in the standard Ruby REXML library[1] used to parse XML. Ruby on Rails will attempt to process incoming XML requests by default, regardless of whether your application utilizes XML explicitly. All customers utilizing Ruby on Rails are encouraged to apply the fix immediately. The patch is available from the official Ruby on Rails Weblog[2] along with instructions appropriate to the different versions of Rails.

[1] - http://www.ruby-lang.org/en/news/2008/08/23/dos-vulnerability-in-rexml/
[2] - http://weblog.rubyonrails.org/2008/8/23/dos-vulnerabilities-in-rexml

But as usual I cannot figure out what the big deal is, what happens if someone utilizes this security hole in one of my many Ror applications?

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Pardot posted:

Also has anyone set up nginx to proxy to different apps, but not using subdomains? Like me.com/app1 me.com/app2? I can't quite get it to work.

The only way to do this is to not have public_html be a symlink, as *nix does not support running two daisy-chained symlinks. Or at least that's what I remember the issue being, there is definitely an issue there whatever the issue is.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I am trying to create a site that is kin to okcupid and need some location based plugin to sort out where cities are and their proximity to one another.

All of the geography based plugins seem to place a lot of emphasis on street names and zip codes, following which it performs and off site lookup using google and whatnot. All I really want is some database tables filled with countries, provinces and cities with the latitude and longitude filled in, then a method which can do lookups based on location and search radius.

Where can I find something more along the lines of and specific to what I need?

For my purposes there is not any reason to be able to type in the city name, a drop down list is ok as that would be close enough.

Help!

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
What the heck I'll just GeoKit it, this seems to be the new way of doing things.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I just felt like popping in on this thread really quick. Doo doop doouuu doo doo! Doo doo doo ooo doo!

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

atastypie posted:

You have to restart your server any time you change your routes file.

That is false, you do have to restart your server anytime you change your environment.rb, database.yml, or vendor directory. Routes can be altered on the f.l.y.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

phazer posted:

Can someone point me in the right direction for doing multiple file uploads in Rails2? I want to have 1 upload field with the ability to add more through AJAX. I'm googling but finding nothing valuable.

Here is a resource that does something like you want. It's not bad but I'd be wary; look at the updated code snippets on the page and read the comments because the video might be old.

http://railscasts.com/episodes/75-complex-forms-part-3

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?

With regard to SVN and github and Capistrano and all that crap, you don't really need to use Capistrano to deploy your application. Find a good host that supports Rails and check out their FAQ section, most of them will walk you though getting your application running through FTP (or SFTP if you prefer) and a terminal window.

My favorite program on os x for doing this is Coda, I don't know if I'd use it for development but it makes it easy to work on files that are server side. It's pricey but there is a demo available that will get you running. On Windows I recommend WinSCP, WinSCP rocks.

Honestly if you try and jump right into Capistrano with your pants off you're going to get decapitated, I know a lot about how Capistrano works and have had to use it a huge number of times after getting 1 on 1 training. I think it is absurd, overly complicated, useless for something as simple as most Rails apps are.

Here is my favorite host's deployment FAQ.

http://wiki.railsplayground.com/railsplayground/show/Troubleshoot+Common+Rails+Deployment+and+Setup+issues

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Flobbster posted:

Thanks for this. I've been reading a little more ("Deploying Rails Applications" from Pragmatic Bookshelf) and if I'm understanding everything it looks like Capistrano does everything over SSH, which means it's out for me -- the host I'm using charges extra for SSH each month, an option that I declined (the site I'm designing is just a simple art site for my dad, so there's no reason for him to pay for something he'll never use, and once the site is deployed I won't need to touch it very often either), so that's why I've been so concerned with a simple "upload and go" method of deployment.

I don't think it is possible to restart the mongrel service your app is running on without SSH and I don't think it is possible to run rake tasks without it. If you run the rake tasks locally, then export and insert the database changes onto the host's phpmyadmin you might be alright. You'd need to contact their support every time that you need to restart the mongrel service.

If I were you I'd pay for SSH or get a better host, charging you to use SSH is a sort of manufactured fake service fee.

A few quick tips for deployment without capistrano.

1) Freeze the plugins, gems and rails to your vendor folder before uploading.
2) To reduce the chance of corrupted files, either gzip your project before uploading it and ungzip on the server or use SFTP/SSH protocol to transfer it.
3) Upload your application somewhere on the server outside of ~/public_html.
4) Set the permissions recursively on the entire application that you uploaded to 755.
5) Some hosts don't like this on writable directories, so you may have to change your log directory and any file storage directories to 777.
6) Manually update the ~/app/public/.htaccess file to reflect the server and the fact you want to use dispatch .fcgi not .cgi as the file being referenced.
7) Check to ensure ~/app/public/dispatch.fcgi has the correct #!bash line.
8) Create the database on the server, update the production config.yml to use the new db settings.
9) Populate the database with rake.
10) Manually update environment.rb to remove the comment before the environment = production thingy.
11) Delete ~/public_html then create a symlink to the ~/app/public directory in its place.
12) Restart mongrel.

If you are developing on a Windows machine then there are a lot more steps that would need to be added to the above list, all other operating systems (*nix/osx) you will be fine.

Alternatively you can go through the motions to use capistrano, but you'll find the above steps to be much faster. No matter what OS you are using capistrano just takes all the stuff you would have to do, adds a lot more convolution to it, then forces you to start over again when you don't configure it not to break itself every time.

Someone probably has had a different experience with Capistrano that I have, but regardless it is bloated and absurd. I was thinking all we really need is a simple bash script that does all this stuff anyone up for it?

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I would pay $5 a month and do, it is not a huge sum of money and you get what you pay for. :)

If they provide you with a utility to restart mongrel services with the click of a mouse it is still a hack but at least they give you something.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I have an Entries model and I have a Votes model. Each Entry has many Votes and each time that an Entry is loaded, the associated Votes will also need to be loaded, is there a way I can use scope to automatically :include => :votes on each request?

Or is this not good practice?

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Thanks for the advice, I am using named_scope now.


I have some restful routes in my application, shorthand it looks like this.
code:
  map.resources :entries
  map.root :controller => 'entries'
Now in my application if I call entries_path the result is a link to /entries when what I really want is to go to / instead. The path /entries should never really come up unless I've specified a entry_id, is there a way for me to tell Rails that the shorter url takes priority?

Before I started using rest Rails was good at picking the shortest url because I would always put the shorter urls lowest in the order.

Or do I have to start explicitly using root_path instead?

Nolgthorn fucked around with this message at 04:53 on Dec 23, 2008

Adbot
ADBOT LOVES YOU

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
That didn't really seem to fix it, my routes are a bit more verbose, let me post in more detail including your suggestion I'm still getting directed to /entries with entries_path.

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.entries '/', :controller => 'entries', :action => 'index', :conditions => {:method => :get}
    entry.resources :comments, :member => {:confirm_destroy => :get}
  end
  map.date ':year/:month/:day', :requirements => {:year=>/\d{4}/,:month=>/\d{1,2}/,:day=>/\d{1,2}/},
      :controller => 'entries', :action => 'show'

  map.root :controller => 'entries'

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