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
NotShadowStar
Sep 20, 2000
You really, really should read the book. The PDF is really cheap. You're thinking Java, and Ruby is the anti-Java. Nothing in Ruby is nowhere near as complicated as you're making it to be, unless it's from a Java refugee that doesn't know better yet.

Adbot
ADBOT LOVES YOU

hostile apostle
Aug 29, 2006
:stadia::stadia::stadia::stadia::stadia:
Stadia didn't outlive SA but it did outlive Lowtax - Happy Birthday Stadia! #ad
:stadia::stadia::stadia::stadia::stadia:
Having an issue getting rvm installed on my Ubuntu machine.

I followed the directions, but the problem is that the script directory which rvm is expected to be in is "$HOME/.rvm/scripts/rvm", but it is actually in "$HOME/.rvm/src/rvm/scripts/rvm"

I modified this code in .bashrc and .bash_profile for the difference, but the system is still expecting rvm to be in the default directory.

code:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"  # This loads RVM into a shell session.
was changed to
code:
[[ -s "$HOME/.rvm/src/rvm/scripts/rvm" ]] && . "$HOME/.rvm/src/rvm/scripts/rvm"  # This loads RVM into a shell session.
My .bashrc file had a return, but I changed that as instructed.

Followed the installation instructions here (http://rvm.beginrescueend.com/rvm/install/) and consulted elsewhere.

Anyone else encounter this issue or know of a solution? TIA

rugbert
Mar 26, 2003
yea, fuck you
Im also having trouble with Ruby on Rails in Ubuntu. I just installed 10.10 desktop (64bit). I installed ruby via apt, installed gem manually, and rails from gem.

I was able to create a new rails project, but when I tried to make models it errors out. It claims that the rails gem isnt installed and to run bundle install.

After running bundle install, the install errors out saying something about not having a file call mkmf. The internet told me that apt did not install ruby1.8-dev. did that which did hte trick, but now im having issues with the sql gem.

Anytime I try to install it, either by adding a line to my gem file or with gem install I get an
code:
 ERROR: Failed to build gem native extension
Any help?

Obsurveyor
Jan 10, 2003

rugbert posted:

Anytime I try to install it, either by adding a line to my gem file or with gem install I get an
code:
 ERROR: Failed to build gem native extension
Have you installed a compiler to be able to build native extensions? I think it is apt-get install build-essential

rugbert
Mar 26, 2003
yea, fuck you

Obsurveyor posted:

Have you installed a compiler to be able to build native extensions? I think it is apt-get install build-essential

Yes indeed. This is what Im getting

code:
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Obsurveyor
Jan 10, 2003

rugbert posted:

Yes indeed. This is what Im getting
mysql-dev libraries installed too?

bitprophet
Jul 22, 2004
Taco Defender
Yup, need libmysqlclient15-dev (or whatever it's named in 10.10, that was the name back in 8.04) and also ruby1.8-dev. I think those two plus build-essential covers everything.

NotShadowStar
Sep 20, 2000

hostile apostle posted:

Having an issue getting rvm installed on my Ubuntu machine.

I followed the directions, but the problem is that the script directory which rvm is expected to be in is "$HOME/.rvm/scripts/rvm", but it is actually in "$HOME/.rvm/src/rvm/scripts/rvm"

I modified this code in .bashrc and .bash_profile for the difference, but the system is still expecting rvm to be in the default directory.

code:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"  # This loads RVM into a shell session.
was changed to
code:
[[ -s "$HOME/.rvm/src/rvm/scripts/rvm" ]] && . "$HOME/.rvm/src/rvm/scripts/rvm"  # This loads RVM into a shell session.
My .bashrc file had a return, but I changed that as instructed.

Followed the installation instructions here (http://rvm.beginrescueend.com/rvm/install/) and consulted elsewhere.

Anyone else encounter this issue or know of a solution? TIA


rm -rf ~/.rvm and start again from
code:
bash < <( curl [url]http://rvm.beginrescueend.com/releases/rvm-install-head[/url] )
If it continues to do it, let Wayne know, he puts his contact info like all over the place.

rugbert
Mar 26, 2003
yea, fuck you

Obsurveyor posted:

mysql-dev libraries installed too?

yup thats it, thanks!

huh, didnt it used to be mysql-dev? I had to install libmysqlclient15-dev.

edit - wtf, ok, I just tried to create a new model, bam it worked. Migrated, checked my sql database and there is a table with that model name. Cool. But for whatever reason, the model file isnt showing up in my models folder?

edit 2 - i just made a second model and that worked. guess ill have to play around

rugbert fucked around with this message at 23:37 on Oct 15, 2010

hostile apostle
Aug 29, 2006
:stadia::stadia::stadia::stadia::stadia:
Stadia didn't outlive SA but it did outlive Lowtax - Happy Birthday Stadia! #ad
:stadia::stadia::stadia::stadia::stadia:

NotShadowStar posted:

rm -rf ~/.rvm and start again from

sweet, this worked thanks.

now a new question:

mysql or sqlite?

I'm using railstutorial.org right now and he uses sqlite, but for the future, what are the pros and cons of each?

Pardot
Jul 25, 2001




hostile apostle posted:

sql or sqlite?

For development use sqlite. It's one less thing to worry about since you don't need to have any sql server running for your app to work.

For production use postgresql. It's the best open source sql server. There's no reason ever to use mysql

However, I'm obligated at this point to pimp couchdb. But if you're also learning rails at the same time, it'll be easier to stick with active record.

rugbert
Mar 26, 2003
yea, fuck you

Master_Odin posted:

Apparently I can't even make something as simple as a mail form.

So I've got two files for it contact_controller.rb, notifier.rb.

Contact controller is a simple:
code:
class ContactController < ApplicationController
	def index
		# get index.html.erb
	end
	
	def create
		
		redirect_to(:controller => 'admin')
	end
end
so when I go to /contact, it loads the index.html.erb file and I see my form and everything. However, when I submit the form, I get a 500 error.

My routes for it:
code:
  map.with_options :controller => 'contact' do |contact|
  contact.contact '/contact',
    :action => 'index',
    :conditions => { :method => :get }

  contact.contact '/contact',
    :action => 'create',
    :conditions => { :method => :post }
  end
My form is:
code:
<form action="/contact" method="post">
any help on the issue since it has to be something obvious I'm sure would be appreciated!


Im with you buddy. I found that same contact form tut, but Im using rails 3 so I dont know how to set those resources. Im just starting out with rails and my loving boss only talks to me like Ive had experience with RoR before.

Anyone know of a good Contact Form guide for rails 3?

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Does anyone here have experience making a versioned API in rails? I'm wondering if there are any sort of best-practices or lessons learned out there as far as organizing routes and controllers and models go.

dustgun fucked around with this message at 17:25 on Oct 20, 2010

NotShadowStar
Sep 20, 2000
You mean like api.clownpenis.fart/v1 and api.clownpenis.fart/v2? Just do a sub-uri deployment on the entire project of each versioned API. Passenger makes this really, really easy.

plasticbugs
Dec 13, 2006

Special Batman and Robin
I have another very rudimentary question. I recently reworked my app in progress which until recently had three separate models called "Game", "Movie", and "Product" - but they all basically had the same controller structure and had nearly identical views and model definitions.

To prevent this repetition, I have created a model called "Thing" and I subclassed it to create "Game", "Movie", and "Product" models.

So my model definition for "Game" looks like this:
code:
class Game < Thing

  def mymethod(something)
    something
  end

end
Now that I've done that, I need a way to separate Games from Movies and Products.

Right now if I do:

code:
Game.all
Rails returns EVERY record in the Things table - which is obviously not what I want. There must be an easy way to return just a list of Games, but ideally without adding a separate column to declare a Thing type that I have to check for. What am I missing?

EDIT: Would I be better off going back to my 3 separate model solution, each having their own table? Meaning, I would not have a very DRY app, but at least I could rely on Rails conventions without much extra hassle.

plasticbugs fucked around with this message at 20:36 on Oct 20, 2010

NotShadowStar
Sep 20, 2000

plasticbugs posted:


EDIT: Would I be better off going back to my 3 separate model solution, each having their own table?


Yes. Don't do what you did. It's clever, but unnecessary. Sometimes DRY goes too far. Also, subclassing doesn't do what you think it does.

If your models are overlapping, then you need to normalize the database anyway.

plasticbugs
Dec 13, 2006

Special Batman and Robin

NotShadowStar posted:

Yes. Don't do what you did. It's clever, but unnecessary. Sometimes DRY goes too far. Also, subclassing doesn't do what you think it does.

If your models are overlapping, then you need to normalize the database anyway.

It looks like a little repetition will likely save me from myself and the quirks of STI. Thanks for your help!

I'll take a look at how I've structured my database to ensure I'm not overly complicating it. Having "Games", "Movies" and "Products" in separate tables seems like it may speed up queries, and will at the very least simplify my queries.

rugbert
Mar 26, 2003
yea, fuck you
I got my contact form working for the most part. I cant get the actionmailer to send the contents of the mailer file tho.

code:

class Notifier < ActionMailer::Base
  default :from => "requests@xxxx.com", :to => "XXXXX@gmail.com"
  default :subject => "Inquiry From XXXXX.com"
  
  def contact_notification(sender)
    @sender = sender
    mail
  end
end
and the name of the file is contact_notification.html.erb. The method and the file just need to be named the same thing right?

plasticbugs
Dec 13, 2006

Special Batman and Robin
I need a login system for my simple CMS site. Instead of rolling my own, I'd like to use an existing library/gem.

Between Authlogic, Devise and Omniauth, which do you guys recommend for an absolute beginner? I was leaning towards Devise. I wanted to avoid rolling my own simply because I think I'd actually learn more by working with modules and figuring out how to integrate them into an existing project (something I haven't quite done yet).

Edit: Holy poo poo. Devise is dumb simple to use and configure. I think I have my answer.

plasticbugs fucked around with this message at 09:32 on Oct 22, 2010

rugbert
Mar 26, 2003
yea, fuck you
Im having trouble with imagemagick on Ubuntu. I apt-get installed it, but I dont get any imagemagick command, so paperclip cant resize images im uploading.

edit - Im a loving rear end in a top hat, I typed in :style instead of :styles


rugbert fucked around with this message at 18:35 on Oct 25, 2010

plasticbugs
Dec 13, 2006

Special Batman and Robin
Please save me from myself. I'm interacting with the Amazon Product Advertising API. One of the item attributes kicks out a verbose, formatted product description.

However, it prints to the browser as a bunch of escaped html entities, like so:
________________
&lt;i&gt;New Super Mario Bros. Wii.&lt;/i&gt; Supporting 2-4 players in side-scrolling co-op and competitive platforming action, and featuring a mix of fan favorites and new characters, new powerups and various input options via the Wii Remote, it is destined to become an instant classic in one of the most beloved game franchises of all-time. &lt;style type="text/css"&gt; .caption { font-family: Verdana, Helvetica neue, Arial, serif; font-size: 10px; font-weight: bold; font-style: italic; } ul.indent { list-style: inside disc; text-indent: -15px; }
________________

I'm sure there's a built in Rails method that cleans this up, and prints to the browser as parsed HTML. I just don't know what it is.

EDIT: I figured it out:

require 'cgi'
CGI.unescapeHTML()

EDIT EDIT: For anyone that cares:

Once you've unescaped the HTML entities, you still need to format your string with the html_safe method. Then, Rails will actually print the formatted HTML to the view.

plasticbugs fucked around with this message at 06:00 on Nov 2, 2010

spiritual bypass
Feb 19, 2008

Grimey Drawer
Are there any good blog engines that run on Rails 3?

NotShadowStar
Sep 20, 2000
Pretty much every rails shop either does a sub-uri/subdomain deployment of Wordpress or roll their own basic one. Wordpress is really the best thing out there, or if you just need something basic it's super fast to whip one out in Rails.

There was Mephisto and Radiant but I don't think either of them work on Rails 3, and both of them were so twisted they were barely Rails anymore. There hasn't been much else because Wordpress is king, easy to install on absolutely any webhost.

NotShadowStar fucked around with this message at 18:54 on Nov 3, 2010

IsotopeOrange
Jan 28, 2003

NotShadowStar posted:

Pretty much every rails shop either does a sub-uri/subdomain deployment of Wordpress or roll their own basic one. Wordpress is really the best thing out there, or if you just need something basic it's super fast to whip one out in Rails.

There was Mephisto and Radiant but I don't think either of them work on Rails 3, and both of them were so twisted they were barely Rails anymore. There hasn't been much else because Wordpress is king, easy to install on absolutely any webhost.

Any good tutorials on doing a sub-uri deployment of Wordpress in Rails 3? Most of the results I found deal with Rails 2.

spiritual bypass
Feb 19, 2008

Grimey Drawer
Yeah, Wordpress is solid but I've just been getting into Ruby (also Rails) and wanted a blog system to match while I'm redoing my website.

Any non-Rails ruby blogging engines that are worthwhile?

NotShadowStar
Sep 20, 2000

IsotopeOrange posted:

Any good tutorials on doing a sub-uri deployment of Wordpress in Rails 3? Most of the results I found deal with Rails 2.

The easiest and most dirty, if you're running in a server that has PHP support, is to make a directory in public/ and dump Wordpress in there. So if you make a directory public/blog and dump Wordpress in there, when you go to http://clownpenis.fart/blog it will pull the Wordpress index.php first.

Otherwise if you're running Passenger on your server, and you drat well should be, you can keep them separated easier. In that instance you make an exception in your server's configuration file for the sub-uri and expicitly turn off Passenger, like this http://www.modrails.com/documentation/Users%20guide%20Apache.html#_passengerenabled_lt_on_off_gt

The most clean I think is to do a sub-domain deployment with a virtual host, and don't enable Passenger or whatever your'e running your Rails app with for that virtual host. That's the most popular way of doing it, and it's perfectly clean since you have a complete separation of concerns if you need to rework your server layout in the future. Like this http://www.modrails.com/documentation/Users%20guide%20Apache.html#_deploying_to_a_virtual_host_8217_s_root

quote:

Yeah, Wordpress is solid but I've just been getting into Ruby (also Rails) and wanted a blog system to match while I'm redoing my website.

Any non-Rails ruby blogging engines that are worthwhile?

You could literally make a simple blog in a couple minutes in Rails or Sinatra or anything, it's one of the 'gee whiz wow!' demos that frameworks always do. It depends on how extensive you want it. If you just want dated content posts it will take you just a couple minutes. Otherwise I can't think of anything because it's really easy to just deploy Wordpress and make a theme that matches the overall look of all of your sites.

NotShadowStar fucked around with this message at 20:06 on Nov 3, 2010

hmm yes
Dec 2, 2000
College Slice
WordPress is really the easiest answer. If you insist it is rails, you can roll your own (with auth, comments, etc.) in a couple of hours.

Radiant is a cool CMS, but as mentioned earlier it has diverged quite a bit from what you would consider normal Rails. It has a very flexible content structure, and can do a lot of really cool things, but it ends up not having good support for a blog. I used to roll with Radiant and have since switched to rolling custom CMSs when needed, since it was faster and easier.

Pardot
Jul 25, 2001




Unless you have several editors and update several times a day, there's absolutely no need for your blog to be dynamic.

I use a ruby gem called webby, which lets me use haml and sass for layouts, do server side code hilighting, etc. It combines down to html, and rsycns to my host with a single rake task. My whole blog is then stored in git.

Were I to do it again though I'd use jeckyll and just use github hosting.

hmm yes
Dec 2, 2000
College Slice
edit: Google solved my question

hmm yes fucked around with this message at 16:37 on Nov 4, 2010

NotShadowStar
Sep 20, 2000
Actually now that I think about it a simple blog engine would be a great way to learn Couch/Mongo.

aquil
Apr 23, 2008
I'm having a terrifyingly stupid problem. I'm migrating (or more accurately rewriting for the practice) a simple blog/vanity site to Rails 3/HAML. One feature of this site is a randomly selected quotation that shows up on every page. I have an admin page to create, update, and delete these quotations, which isn't working properly. When I try to update a quotation, it thinks I'm trying to call the destroy action instead. When I explicitly tell the form_for to call the update action, it claims one doesn't exist, despite it obviously showing up in rake routes. I didn't have this problem in my Rails 2/ERB iteration of the site.

I'm sure I'm just doing something stupid, but I have no idea what. Help would be appreciated.

Here's the relevant code:

The quotes index view:
code:
...
  - @quotes.each do |q|
    = form_for q do |f|
      %tr
        %td #{ f.text_field :quote }
        %td #{ f.text_field :quoter }
        %td #{ f.submit "Update" }
        %td #{ button_to "Delete", q, :confirm => "Are you sure?", :method => :delete }
  ...
The quotes controller's update function:
code:
  def update
    @quote = Quote.find(params[:id])
    if @quote.update_attributes(params[:quote])
      flash[:notice] = "Quote updated successfully."
    else
      flash[:alert] = "Quote update failed!"
    end
    redirect_to quotes_url
  end

spiritual bypass
Feb 19, 2008

Grimey Drawer

NotShadowStar posted:

Actually now that I think about it a simple blog engine would be a great way to learn Couch/Mongo.

Good idea. Time to have some fun...

Pardot
Jul 25, 2001




code:
...
  - @quotes.each do |q|
    %tr
      = form_for q do |f|
        %td= f.text_field :quote
        %td= f.text_field :quoter
        %td= f.submit "Update"
      %td= button_to "Delete", q, :confirm => "Are you sure?", :method => :delete
  ...
button_to creates a new form and a single button inside of it. HTML can't have a form nested in a form. If you move the button_to outside of the form, that should fix it.

And not to be that guy, but tables?

edit: show off the %element= feature of haml

Pardot fucked around with this message at 07:22 on Nov 6, 2010

rugbert
Mar 26, 2003
yea, fuck you
Why does rails support on shared hosting suck so much?

I have one dude with Media Temple and to get rails running it is like performing open heart surgery. And Im trying to test out another site on go daddy shared hosting and while it seems pretty simple my rails app cant actually be found after Ive uploaded to the newly created rails folder.

I think im going to move these guys over to linode or something.

spiritual bypass
Feb 19, 2008

Grimey Drawer
Lithium supports Rails on their shared hosting plans, in case you don't really need a VPS.

NotShadowStar
Sep 20, 2000

rugbert posted:

Why does rails support on shared hosting suck so much?

I have one dude with Media Temple and to get rails running it is like performing open heart surgery. And Im trying to test out another site on go daddy shared hosting and while it seems pretty simple my rails app cant actually be found after Ive uploaded to the newly created rails folder.

I think im going to move these guys over to linode or something.

fart

It's mostly because shared hosts don't give a poo poo, it's really really easy with Passenger, the module is brain dead simple to install and enabling is just another directive in the VirtualHost configuration.

rugbert
Mar 26, 2003
yea, fuck you

rt4 posted:

Lithium supports Rails on their shared hosting plans, in case you don't really need a VPS.

Its not slow is it? I have a wordpress on a godaddy account thats painfully slow.

NotShadowStar posted:

fart

It's mostly because shared hosts don't give a poo poo, it's really really easy with Passenger, the module is brain dead simple to install and enabling is just another directive in the VirtualHost configuration.

Huh, well the price is right for what I need it for. When it says 20gigs database does that mean hosting space?

NotShadowStar
Sep 20, 2000
It means what it says, the size of your database tables total.

Heroku is a bit odd, it pre-compiles your app to a 'slug' when you push it and then loads the slug onto a read-only filesystem. Most apps are about 10-30 meg. Heroku is really really bad at serving static content. If you need attachments or other file type business you should use Amazon S3 or some such. I use S3, it's extremely easy and dirt cheap. Using Heroku for the Rails app and S3 for static assets, speed is not an issue.

spiritual bypass
Feb 19, 2008

Grimey Drawer

rugbert posted:

Its not slow is it? I have a wordpress on a godaddy account thats painfully slow.

I can't say much except that everything there has always been really responsive for me. There's also goon deals available in SA-Mart.

Adbot
ADBOT LOVES YOU

IsotopeOrange
Jan 28, 2003

NotShadowStar posted:

It means what it says, the size of your database tables total.

Heroku is a bit odd, it pre-compiles your app to a 'slug' when you push it and then loads the slug onto a read-only filesystem. Most apps are about 10-30 meg. Heroku is really really bad at serving static content. If you need attachments or other file type business you should use Amazon S3 or some such. I use S3, it's extremely easy and dirt cheap. Using Heroku for the Rails app and S3 for static assets, speed is not an issue.

Heroku does allow you to write to the tmp directory, but that's it.

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