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
MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
Ruby on Rails (aka Rails)


While I'm admittedly still an amateur web developer, I've been a professional programmer for years, and I've always dabbled in web development. I'm currently a senior at UConn, and I've been working on an independent study project with a professor to create a simple two tier web application (eventually for my own purposes; the project is catered to my interests).

I started out the project using javascript/ajax/php/css/sql, and got a simple semblance of a working webapp up after a month or so. Adding functionality was slow going, in part because I was new to php, and because I'm a bit clumsy with debugging web applications in general.

Well, I was reading some rogue post here in SH/SC, where some wise fella said something along the lines of "you'd never run into this problem if you were using rails, and it would have taken you 10x less time to get here". Well this prompted ol' mrsaturn to start reading.

Rails? What is rails?
Rails is really just a streamlined and simplified way to create web applications that are heavily database dependent. The syntax is simple, installation is a breeze, and it's got a decent learning curve. It can run on a windows machine or linux, as well as ol' Mac OSX.

With Rails,
  • You can have a working web applicaiton up in less than a half hour
  • You'll scarcely have to write a line of SQL code (I have yet to with my app)
  • Browser compliance is really not an issue. It just works.
  • You can easily use Ajax to spice up your pages!
  • Many plugins are available which can expand your built in rails functions.

Resources
  • http://www.rubyonrails.org/ - The home of Ruby On Rails. Find out how to install a rails server on your machine, and how to get started coding in rails!
  • http://www.ruby-lang.org/en/ - Rails is built on top of the ruby language. Ruby's elegant, simple, and powerful. Go here to learn about it's specific syntax. I suggest familiarizing yourself with Ruby, since some things won't look too apparent if you're a C#/Java programmer like I [was].

Applications that Use Rails
Here's some sample apps that use rails (I don't own any of these, they're just to show how drat cool it is)

Typo
is a web blogging service


Worth note
I'm currently working on integrating Hobo into my application. Hobo is an application builder for rails. It's basically the easiest way to get a user interface (log in/log out, etc) into your pages without having to think about it, and it works. The development team for hobo is very responsive, and helpful to my newbie woes. It's also got great ajax stuff built in, like the ability to edit fields in a record on the fly, if you're the right user. Check out their screencasts.

So yeah, I mean, I'm in love with rails. Use this thread for whatever you want - :fap: over it, ask for help, tout its abilities, or whatever you see fit. If y'all have working webapps that use rails, or want me to include them in the OP, let me know!

MrSaturn fucked around with this message at 19:11 on Aug 8, 2007

Adbot
ADBOT LOVES YOU

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
Fixed the link, thanks =)
Are there any experienced hobo users here? I'm currently filling up a thread in their dev forum because I can't get textile to work with it =/

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
Hey, a rails question!

so I'm trying to create a new model in my application. It's going to be a hobo model, which I've created in the past. For whatever reason, I can't get
code:
rails script\generate hobo_model blogpost
to do anything!

It just outputs like this:
code:
c:\ruby\rails_apps\myapp>rails script\\generate hobo_model blogpost
      exists
      create  app/controllers
File exists - script\\generate

c:\ruby\rails_apps\myapp>
note I'm running this in windows, and I have run use_ruby.cmd, so I'm in the rails environment, or whatever.

What am I doing wrong?

MrSaturn
Sep 8, 2004

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

Scarboy posted:

Why are you prefixing script\generate by rails? It should be ruby if anything.

touche. It was supposed to be ruby. Brain fart, I guess. That fixed it!

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
Speaking of all this migration business, how can I use rake db:migrate to just... add a field to a table? I'm still heavily developing my application, and I often find the need to add columns (as I develop features), and I don't want to have to wipe the contents of my db each time. Often rake db:migrate doesn't seem to do anything.

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
Ah, thanks!

Regarding migrations, to the naysayers, seriously, look into hobo. this is coming in the next release!

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
Let's say I've got an item called a house in my database. I want a house to be able to create a room. What syntax do I have to use to get the user that created the house, given only the house object? I thought it'd be like
php:
<?
:User.find(House['user_id'])
?>
but that doesn't seem to work. I guess I don't have a grip on this yet. Help?

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
where would I put :include=>user ?
edit: see the problem here is I'm trying to set hobo's
set_creator_attr to :User.find(venue['user_id']) and I'm getting a
code:
 NameError

undefined local variable or method `venue' for Listing:Class
on this code
php:
<?
set_creator_attr :User.find(venue['user_id'])
?>

MrSaturn fucked around with this message at 19:26 on Aug 15, 2007

MrSaturn
Sep 8, 2004

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

Scarboy posted:

Here's an example:

@houses = House.find(:all, :include => :user)

and your new favorite page:
http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000992

well the problem with that call is that I'm in a room, and I have a valid reference to a house, but not to a user. so the :include => :user part wouldn't work, right?

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
yeah, that's kinda like it, though the syntax is a bit different because of hobo. it turns out my problem was a mound of different things, but the eventual syntax is this:

House.find(:first,:conditions=>[ "user_id = ?", user['user_id']])


out of curiosity, would I be better of replacing my belongs_to :user to a delegate? I've never used delegate.

MrSaturn
Sep 8, 2004

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

skidooer posted:

You probably don't want to replace a belongs_to with a delegate, but it's hard to say for sure without seeing it in context.

Well, a room really does only belong to a house, but hobo's user model makes it so that it verifies who can create what using user objects. This is such an odd specific problem, I really appreciate your help. I think I have it working decently for now, though. Thanks so much for your help, the hobo forums really weren't replying.

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
I just broke something when I updated rails from the gem [to edge rails] and I can't figure on how to fix it.... here's what my error log shows:

code:
DISPATCHER FAILSAFE RESPONSE (has cgi) Mon Sep 03 11:35:23 -0400 2007
  Status: 500 Internal Server Error
  A secret is required to generate an integrity hash for cookie session data. Use config.action_controller.session = { :session_key => "_myapp_session", :secret => "some secret phrase" } in config/environment.rb
    C:/ruby/rails_apps/jivewise2/vendor/rails/actionpack/lib/action_controller/session/cookie_store.rb:54:in `initialize'
    C:/ruby/ruby/lib/ruby/1.8/cgi/session.rb:273:in `new'
    C:/ruby/ruby/lib/ruby/1.8/cgi/session.rb:273:in `initialize_without_cgi_reader'
    C:/ruby/rails_apps/jivewise2/vendor/rails/actionpack/lib/action_controller/cgi_ext/session.rb:29:in `initialize'
    C:/ruby/rails_apps/jivewise2/vendor/rails/actionpack/lib/action_controller/cgi_process.rb:124:in `new'
    C:/ruby/rails_apps/jivewise2/vendor/rails/actionpack/lib/action_controller/cgi_process.rb:124:in `session'
    C:/ruby/rails_apps/jivewise2/vendor/rails/actionpack/lib/action_controller/cgi_process.rb:156:in `stale_session_check!'
    C:/ruby/rails_apps/jivewise2/vendor/rails/actionpack/lib/action_controller/cgi_process.rb:111:in `session'
    C:/ruby/rails_apps/jivewise2/vendor/rails/actionpack/lib/action_controller/base.rb:1117:in `assign_shortcuts_without_flash'
    C:/ruby/rails_apps/jivewise2/vendor/rails/actionpack/lib/action_controller/flash.rb:174:in `assign_shortcuts'
    C:/ruby/rails_apps/jivewise2/vendor/rails/actionpack/lib/action_controller/base.rb:488:in `process_without_filters'
    C:/ruby/rails_apps/jivewise2/vendor/rails/actionpack/lib/action_controller/filters.rb:683:in `process_without_session_management_support'
    C:/ruby/rails_apps/jivewise2/vendor/rails/actionpack/lib/action_controller/session_management.rb:122:in `process'
    C:/ruby/rails_apps/jivewise2/vendor/rails/actionpack/lib/action_controller/base.rb:346:in `process'
    C:/ruby/rails_apps/jivewise2/vendor/rails/railties/lib/dispatcher.rb:39:in `dispatch'
    C:/ruby/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:78:in `process'
    C:/ruby/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in `synchronize'
    C:/ruby/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in `process'
    C:/ruby/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:618:in `process_client'
    C:/ruby/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `each'
    C:/ruby/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `process_client'
    C:/ruby/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run'
    C:/ruby/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `initialize'
    C:/ruby/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `new'
    C:/ruby/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run'
    C:/ruby/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `initialize'
    C:/ruby/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `new'
    C:/ruby/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `run'
    C:/ruby/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:271:in `run'
    C:/ruby/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `each'
    C:/ruby/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `run'
    C:/ruby/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:127:in `run'
    C:/ruby/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/command.rb:211:in `run'
    C:/ruby/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:243
    C:/ruby/ruby/bin/mongrel_rails:16:in `load'
    C:/ruby/ruby/bin/mongrel_rails:16
It looks like I have to set some keyword for my cookie? Where and how do I do that?

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
This is a question so stupid, I can't believe I'm asking it, but:

how do I link to a static page within my domain? I want to make a contact page for my application, but there's no dynamic content to be put on it. I tried making app/views/contact/index.rhtml, and I got a routing error when I pointed my browser there.

where do I put a page to link to, say
localhost:3000/contact?

MrSaturn
Sep 8, 2004

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

atastypie posted:

it goes in /public

does it go as /public/info.rhtml
or
/public/info/index.rhtml?

I'm not really getting either to work.

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
I'm very suddenly having a very odd problem. I'm running instant rails on vista, and as of last night, I can't start up mySql because
code:
---------------------------
MySQL
---------------------------
Either Apache or MySQL cannot run because another program is using it's port.
---------------------------
OK   
---------------------------
how do I figure out what port is being blocked, what's blocking it, and how to change that in mySQl or the other program?

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
IIS is definitely off. I just checked.

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?

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)

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.

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?

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:

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

MrSaturn
Sep 8, 2004

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

SeventySeven posted:

I've got a controller set up like this:

code:
def method1
  # Does some processing then...
  redirect_to :action => "method2"
end

def method2
  if request.xhr?
  elsif request.post?
  else
  end
end
Basically, I'm trying to determine the entry point for method2 (which can also come from the browser). Obviously I know about the request object, but is there any way I can tell if method2 was entered from a redirect?

could you set a boolean value in method1 to true, so you know that when that value's true, it came from method 1? (then just reset it to false at the end of method 2)

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
I've got another question: I'm trying to add an rss feed to my blog, but I'm missing something. In my blogposts controller, I added the following code (from http://paulsturgess.co.uk/articles/show/13-creating-an-rss-feed-in-ruby-on-rails):

code:
  def rss
    @blogposts = Blogpost.find(:all, :order=> "id DESC")
    render_without_layout
    @headers["Content=Type"] = "application/xml; charset utf-8"
  end
However, when I go to http://puddl.es:3002/blogposts/rss, I get "Can't find Blogpost: rss"

What'm I doing wrong? I've restarted my servers, I've tried putting the def rss in the frontpage's controller and moving the accompanying rss.rxml file to that view folder, and nothing seems to fix this.

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
ah I got it working now, I just set it up under a new controller. Is RSS a reserved controller name?

if you want to see it, it's at http://puddl.es:3002/rssfeed

This is pretty cool. I'm learning how to do about one new thing a week on rails, given the free time I have. I do rather enjoy all this. I think next I'm going to work on my display pages for each blogpost, then do some interesting ajax stuff. You guys are great help so far! Thanks! :h:

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.

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.

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)

MrSaturn
Sep 8, 2004

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

bmoyles posted:

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

lord, what the devil is he on about? poor guy, lovely people ruined something that could have done him well, it looks like.

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
Ok, so I made the plunge and bought some hosting on dreamhost. I've moved one of my rails applications over, but I don't know how to tell it to run on the default port for my domain.

Essentially, at the moment you can access it at http://puddl.es:3000 but I just want to be able to get to it from http://puddl.es

how do I do that? I've tried to do ruby script/server -p 80, but that doesn't work (it tells me I have permission denied on Bind())

MrSaturn
Sep 8, 2004

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

Austria posted:

DreamHost is a terrible Rails host.
horay =/

I guess what I want to know is how do I set up my .htaccess to default to that running application... if I point to public/dispatch.fcgi nothing ever loads.

MrSaturn
Sep 8, 2004

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

Anal Wink posted:

I've used acts_as_solr before. What's the difference between ferret ad acts_as_solr? They both use lucene if I'm not mistaken.


code:
RewriteEngine On
RewriteRule ^(.*)$ [url]http://127.0.0.1:some_port/[/url]$1 [P,L]
Then have a mongrel running at some_port. Don't use fcgi.

problem is, mongrel isn't an installed gem, and they didn't allow me to run a daemon task with just ruby script/server -d, I don't think it'll work with mongrel either...

MrSaturn
Sep 8, 2004

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

Zaxxon posted:

I'm a total newb to web programming in general, and I wanted to get started with Ruby on Rails, but every tutorial I read kind of comes from the assumption that a person will allready know a lot about web programming. They all have this "see with PHP it would be super hard to integrate your .xml file and your .wtf" but in rails all you do is edit Blah.rhtml, and then put a tag in your Db.yml file, and I have no idea what the gently caress any of this poo poo is.

I'm good at programming and ruby is a breeze to pick up, but lord all these web standards cause my head to spin. Is there a good tutorial about beginning web programming with Rails assuming one has never done it with anything else?

Well, if you're not familiar with html and css to begin with, I'd recommend you at least go through the tutorials at https://www.w3schools.org. Failing that, look up an article called "Rolling with ruby on rails". That's where I started.

Adbot
ADBOT LOVES YOU

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
I still use hobo a good bit, but the change to rails 2.0 kinda broke all of my applications, for one reason or another, so I had to start from scratch with a lot of things. I really need to set up subversion.

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