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
will_paginate itself is a Module and it extends ActiveRecord::Base directly. We generally don't do that anymore.

https://github.com/mislav/will_paginate/blob/master/lib/will_paginate.rb

Adbot
ADBOT LOVES YOU

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
This is the solution I've settled on, attached if anyone is interested. I've decided to paginate in the view and it turns out that works great.

http://pastie.org/1514717

maskenfreiheit
Dec 30, 2004
.

maskenfreiheit fucked around with this message at 21:32 on Apr 28, 2019

BrokenDynasty
Dec 25, 2003

GregNorc posted:

So I need to crawl some websites with an actual full fledged web browser. (Looking at stuff related to cookies, and flash, so wget or curl would not suffice)

Basically I need to automate opening firefox, navigating to a site, and interacting with that site. I'm guessing this has been done before, anyone know of a library?

Fake?

canned from the band
Sep 13, 2007

I'm a man of intensity. Of cool, and youth, and passionately

GregNorc posted:

So I need to crawl some websites with an actual full fledged web browser. (Looking at stuff related to cookies, and flash, so wget or curl would not suffice)

Basically I need to automate opening firefox, navigating to a site, and interacting with that site. I'm guessing this has been done before, anyone know of a library?

Sounds like Selenium might be a good fit for this.

maskenfreiheit
Dec 30, 2004
.

maskenfreiheit fucked around with this message at 21:32 on Apr 28, 2019

hmm yes
Dec 2, 2000
College Slice
The RSpec Book has a bunch of chapters on using cucumber/webrat/selenium to test views in Rails. It's a great place to start, although I don't know with certainty if they will let you test what you need.

gce
Oct 11, 2004
How does Rails 3 Way compare to the Pragmatic Programmer's Agile series? I have a good understanding of basic Rails concepts but get a little lost when I actually try to put code into action.

Obsurveyor
Jan 10, 2003

gce posted:

How does Rails 3 Way compare to the Pragmatic Programmer's Agile series? I have a good understanding of basic Rails concepts but get a little lost when I actually try to put code into action.
Agile Web Development with Rails, 4th Edition is extremely basic, if you ask me. On par but inferior to Rails 3 Way's complementary book "Ruby on Rails 3 Tutorial"(also free at railstutorial.org) from the same publisher. I liked the Rails Tutorial quite a bit more than Agile Web and I am planning on reading Rails 3 Way when I get a chance. Do not get me wrong, I love and own a ton of PragProg books, I just think Agile Web falls short of something that is free. The RSpec Book, for instance, is awesome and should be an immediate buy imo.

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys
Not perfectly on-topic, but I figure a lot of people would know the answer to this:

In textmate, is there a way to auto-insert a closing 'end' when I open a block? I know I have snippets for things like "def[tab]", which will insert a closing 'end' and a blank line in between.

But TM clearly knows when I open a block, by increasing indentation, and when I end a block, by decreasing indentation. Is there a way to make it auto-insert the code for the end of the block?

NotShadowStar
Sep 20, 2000
do[tab]

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys

NotShadowStar posted:

do[tab]
Yeah, but is there a way to do that without snippets, like TM does with parentheses or quotes? The problem with snippets is that, a), I need to retrain my fingers to use tab instead of return and, b), the snippet isn't always what I want. For example, with 'do', it always has a "|variable|" statement after the "do". I can just backspace over this, but that's still an extra keystroke and branch in my thought pattern that I'd rather not have.

Plus, there are blocks (using the general use of the term rather than specific Ruby do/end blocks) that TM doesn't have snippets for. For example, Cucumber "Scenario: " blocks, which are ended with a line containing the same indentation as the start of the block (which is a whole other problem right there.)

Pardot
Jul 25, 2001




comedy switch-to-vim-and-use-endwise response

NotShadowStar
Sep 20, 2000

Magicmat posted:

Yeah, but is there a way to do that without snippets, like TM does with parentheses or quotes? The problem with snippets is that, a), I need to retrain my fingers to use tab instead of return and, b), the snippet isn't always what I want. For example, with 'do', it always has a "|variable|" statement after the "do". I can just backspace over this, but that's still an extra keystroke and branch in my thought pattern that I'd rather not have.

Plus, there are blocks (using the general use of the term rather than specific Ruby do/end blocks) that TM doesn't have snippets for. For example, Cucumber "Scenario: " blocks, which are ended with a line containing the same indentation as the start of the block (which is a whole other problem right there.)

Auto-indent doesn't work by looking at if you're in a block, it works by comparing the line you just hit return from and see if it should match indentation or not. That's it. Textmate doesn't know or care if you're in our out of parentheses, it just auto-inserts or deletes matching ones. Textmate doesn't automatically do this because sometimes you want do |f|; yield; end; and sometimes you want {|f| yield }. If it really bugs you, you can always use {|f| } and drive anyone who's working on your code bonkers.

Oh and don't get me started on Vim's indentation. I can't fully switch to Vim because the HTML and PHP indentation is completely useless. Oh sure there's always 'but you can fix it yourself!' but I don't know that much about Vim internally and I'm spending too much of my life fixing other people's crap anyway.

Obsurveyor
Jan 10, 2003

Pardot posted:

comedy switch-to-vim-and-use-endwise response
Oh god, thank you!

edit: A bit sad, it does not do proper indentation.

Obsurveyor fucked around with this message at 02:11 on Feb 3, 2011

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Pardot posted:

comedy switch-to-vim-and-use-endwise response

Sorry but I not only paid more ONLY to use textmate, but it's also the only reason I am using a mac.

rugbert
Mar 26, 2003
yea, fuck you

Nolgthorn posted:

Sorry but I not only paid more ONLY to use textmate, but it's also the only reason I am using a mac.

Yea, I use a mac with textmate at work and its great. Redcar for linux is a decent textmate clone for the linux users.


Soooooo flash messages, how the gently caress do they work? Do I pass messages in via controller? Because thats what I thought the :message method in my validations was for.

I want my error messages to be as specific as possible.

skidooer
Aug 6, 2001

rugbert posted:

Soooooo flash messages, how the gently caress do they work? Do I pass messages in via controller?
flash is exactly like session, except the value is only available on the very next page load.

It is a good way to pass info between pages during a redirect, such as a message stating that the record was successfully created. You typically wouldn't use it to display validation error messages as the standard procedure, and easiest method, is to redisplay the form on the same action handling the model validation - giving full access to the model object.

And yes, the controller is the usual place to set your flash values.

8ender
Sep 24, 2003

clown is watching you sleep
Well this is a big shame:

http://netbeans.org/community/news/show/1507.html?utm_source=netbeans&utm_campaign=welcomepage

I absolutely love the Ruby integration in Netbeans. This is heartbreaking. I know that Ruby and Rails don't necessarily really need an IDE but Netbeans has made a lot of day to day tasks like managing project files, committing code, and generating things a lot quicker.

Anyone have any suggestions on a good Ruby centric IDE that plays nice on Mac?

NotShadowStar
Sep 20, 2000
It depends on what you want out of an IDE. I know there's LOL VIM LOL, and myself for many years I couldn't bring myself to do it. But with this and this saying exactly how I felt about it, and Yehuda's Janus addins to MacVim, VIM really has been nice so far if you're working in strictly Ruby land. This screencast/lecture also really helped me get into the mindset, and the person who is running Vimcasts is writing a book; so that should be awesome.

Be warned that outside of Ruby land Vim gets crappy. PHP or bare HTML is really, really frustrating. I get the impression that the Ruby community is just like the gay community, move into somewhere that's dank and needs repair (Vim, Java, Web development etc.), make everything awesome and move on.

Obsurveyor
Jan 10, 2003

NotShadowStar posted:

Be warned that outside of Ruby land Vim gets crappy. PHP or bare HTML is really, really frustrating. I get the impression that the Ruby community is just like the gay community, move into somewhere that's dank and needs repair (Vim, Java, Web development etc.), make everything awesome and move on.
What exactly have you gotten frustrated with, using vim and HTML? I have been using it forever but for the last few years I have been using viemu and Visual Studio for PHP/HTML so I am a bit rusty on the vim side.

Yesterday I spent an hour trying to get my favorite mapping ever to work properly when it turned out to be an issue with putty and vim. I had to write:
code:
nnoremap / :call FixUnhighlight()<CR>/

function! FixUnhighlight()
  nnoremap <silent> <Esc> :noh<CR><Esc>
  nunmap /
endfunction
If I just try to map Esc to :noh, it fires every time I start vim because something is asking putty for an ANSI code(I think that is what this is) and putty is sending back: ^[[>0;136;0c

rugbert
Mar 26, 2003
yea, fuck you
Ok, so Im trying to display all new tattoos on this site's home page and set it up so clicking on said tattoo takes you to the artist's page.

my models are set up as User has_many Tattoos with the Tattoo table relating to users with a user_id field.

I thought I could try this:
code:
@tattoos = User.all.tattoos.all
so in the view I could loop through all new tattoos and link_to each artist's page with the username field (thats on the User table). But rails keeps telling me that tattoos is an undefined method. Im confused because in my admin section this works:
code:
u = current_user
@tattoos = u.tattoos.all

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
For rails 3:
code:
@tattoos = Tattoo.includes(:user).limit(50)

Rails 2:
code:
@tattoos = Tattoo.find(:all, :limit => 50, :include => :user)
and then get the username from tattoo.user.username in your loop, unless I'm misunderstanding something.

dustgun fucked around with this message at 18:15 on Feb 11, 2011

TunanFish
Nov 22, 2002
Idle means not in use, and I got into Princeton? Please, somebody, anybody, end my meaningless existence!
A silly question from a new Ruby & Rails user: I'm trying to install RubyOSX 1.2 to my Powerbook with Tiger, and everything goes fine until I attempt to update RubyGems. The RubyonRails Wiki tells me to type the following into Terminal:

$ sudo gem install rubygems-update
$ sudo update_rubygems

... which I do, but both of these return the following error message:

"ERROR: While executing gem ... (Gem::RemoteSourceException)
HTTP Response 302"

I've searched until how to fix this, and have tried to update RubyGems, but even then I'm still getting problems. I've tried to install Gems from scratch, but cannot figure out how to run ruby setup.rb from Terminal. (Note: I haven't used Terminal in a long time and recognize that I'm likely missing something quite simple here.) Can anyone offer suggestions on how to proceed from here?

NotShadowStar
Sep 20, 2000

TunanFish posted:

RubyOSX

Undo everything you did and use RVM instead.

TunanFish
Nov 22, 2002
Idle means not in use, and I got into Princeton? Please, somebody, anybody, end my meaningless existence!

NotShadowStar posted:

RVM

Thanks for the tip. It's going well thus far, but as I'm just beginning to set things with a "rails server" command inside the directory I'm working in, I get the following error:

"Could not find gem 'sqlite3 (>= 0, runtime)' in any of the gem sources listed in your Gemfile."

I've looked around on a number of forums for help with this, but haven't found a solution that resolves the problem. I'm running Ruby 1.9.2 and gems -v gives me '1.5.0' Sorry for a n00bish question again!

NotShadowStar
Sep 20, 2000
'gem install bundler'
and
'bundle install' in your Rails directory.

TunanFish
Nov 22, 2002
Idle means not in use, and I got into Princeton? Please, somebody, anybody, end my meaningless existence!
There now appear to be two related problems.

First, when I try bundle install, I get this:

'Installing sqlite3 (1.3.3) with native extensions /Users/mary/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:529:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

/Users/mary/.rvm/rubies/ruby-1.9.2-p136/bin/ruby extconf.rb
checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... yes
checking for rb_proc_arity()... yes
checking for sqlite3_initialize()... no
sqlite3-ruby only supports sqlite3 versions 3.6.16+, please upgrade!'

Then, as a result, when I attempt to do 'rails server,' I get this:

Could not find gem 'sqlite3 (>= 0, runtime)' in any of the gem sources listed in your Gemfile.

Currently, I have SQLite 3.4.0, but can't figure out how to update it. Thanks!

hmm yes
Dec 2, 2000
College Slice
Could be path conflicts. Check that your old ruby and gems files in /usr/bin are deleted, and that your paths are updated in your ~/.profile and apache conf file.

NotShadowStar
Sep 20, 2000
Also be sure to read the RVM documentation very, very carefully, in particular what it says on adding a line to your .bash_profile.

Though on the other hand the sqlite3 libraries available on Tiger could be very old. In that case, install Homebrew and then do 'brew install sqlite'.

Also your PPC Powerbook is reaching the end of the line, especially when 10.7 is out. Your best hope is Leopard but it's a slow beast. Something to consider if you're going to be doing future development work in OSX.

bitprophet
Jul 22, 2004
Taco Defender

NotShadowStar posted:

In that case, install Homebrew and then do 'brew install sqlite'.

Unless the Tiger fork is more robust than I remember, brew is Leopard and up :(

Seconding the point that a PPC Mac is...really not very feasible for modern development. You can almost definitely pick up an early Intel system for cheapish nowadays...

TunanFish
Nov 22, 2002
Idle means not in use, and I got into Princeton? Please, somebody, anybody, end my meaningless existence!
Thanks for all of the advice! I made a typo up above, so I'm not quite as backwards as I indicated - I'm using a MacBook Pro circa 2006, so it's an Intel processor. After reading these replies and looking at various other sources, it seems like life is going to be difficult doing any development work without 10.6, so I'm thinking of upgrading ASAP and perhaps getting a RAM upgrade to boot. In your opinion, does that make sense - go to 10.6, install Homebrew, and go from there?

NotShadowStar
Sep 20, 2000
Ah you said Powerbook and were talking about Tiger so all signs pointed to a PPC Powerbook. Snow Leopard is $30 and will be supported for quite a while, so it's very worth it.
When you do upgrade, don't do an upgrade or archive and install, just back up what you need before and erase and install.

rugbert
Mar 26, 2003
yea, fuck you

dustgun posted:

For rails 3:
code:
@tattoos = Tattoo.includes(:user).limit(50)

Rails 2:
code:
@tattoos = Tattoo.find(:all, :limit => 50, :include => :user)
and then get the username from tattoo.user.username in your loop, unless I'm misunderstanding something.

Oh cool thanks!

Is there a good Add This gem or something? I tried adding the add this code to my posts but when you click it, it likes the current page and not the current post :/

TunanFish
Nov 22, 2002
Idle means not in use, and I got into Princeton? Please, somebody, anybody, end my meaningless existence!
Sorry for yet more stupid questions, but I'm still running into the same problems with 10.6 installed (on an Intel MacBook Pro). Can someone point me to a walkthrough for installing Rails that starts from zero? I have attempted both to download RVM from:

ttp://rvm.beginrescueend.com/releases/rvm-install-head

but do not have Git, and cannot seem to install it properly, and the manual instruction steps are not working, even after adjusting the .bash_profile.

Sorry for obnoxious questions - I just feel like attempting to install Rails, which seemed so simple, has already consumed several hours. I'm just looking for a simple walkthrough -- following the steps with RVM and those on the Rails website has not led it to function.

NotShadowStar
Sep 20, 2000
Install homebrew, then 'brew install git'. Developer tools, as always, needs to be installed.

(Rails is actually built in OSX > 10.5, but it's old and you should be using Ruby 1.9.2 anyway)

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come

rugbert posted:

Oh cool thanks!

Is there a good Add This gem or something? I tried adding the add this code to my posts but when you click it, it likes the current page and not the current post :/
Can you post the code you're using?

TunanFish
Nov 22, 2002
Idle means not in use, and I got into Princeton? Please, somebody, anybody, end my meaningless existence!
I get multiple error messages when I attempt to install Homebrew:

1. Warning: Xcode is not installed! Builds may fail!

(I downloaded and installed the latest version of Xcode from Mac Developer Tools while still running 10.4, so I'm not sure where this is coming from.)

2. Warning: It appears you have MacPorts or Fink installed.

(I try to uninstall Macports using the following instructions [http://guide.macports.org/#installing.macports.uninstalling], but it tells me 'no suitable image found.' and quits.)

3. Error: Failure while executing: ./configure --disable-debug --prefix=/usr/local/Cellar/wget/1.12 --disable-iri

'It looks like an autotools configure failed.'

rugbert
Mar 26, 2003
yea, fuck you

dustgun posted:

Can you post the code you're using?

Its just the code supplied from addthis.com.
code:
<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_counter addthis_pill_style"></a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4d5869842abb4011"></script>
<!-- AddThis Button END -->
Im guessing that javascript just connects to whatever social media site you want (facebook, twitter) and likes the current url. But I assumed there would be a sweet gem with similar features

Adbot
ADBOT LOVES YOU

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys
I'm having some trouble with Nokogiri.

I have a HTML::Builder to create a new HTML document, and inside it I'm looping over a collection with the #each method. Basically, if the current loop item has some attribute, create a new div in the document to contain some HTML, and have that div contain all subsequent loops' HTML until we hit another loop item that fulfills our requirements, where we create another div, etc.

Hard to explain, but imagine I have the following array of array:
code:
[['one', true],
['two', false],
['three', false],
['four', true],
['five', false]]
I would then want an HTML doc looking like this:
code:
<html>
<head></head>
<body>
  <div>
    <span>one</span>
    <span>two</span>
    <span>three</span>
  </div>
  <div>
    <span>four</span>
    <span>five</span>
  </div>
</body>
</html>
I'm currently trying to do something like,
code:
...
# 'doc' is the HTML::Builder object passed into the block of HTML::Builder.new()
container_node

item.each do |foo|
  if(foo[1]) then
    container_node = doc.div
  end

  Nokogiri:::HTML::Builder.with(container_node) do |bar|
    bar.span foo[0]
  end
end
...
But the results of doc.div don't appear to be a regular XML::Node I can use with Builder.with(). I also considered trying to create a new node without a document, then attaching it to the container_node at the end of every loop, but the results of doc.div is Nokogiri::XML::Builder::NodeBuilder, and I'm not sure if I can attach a child node to that easily. Plus, I'm not sure the proper way to go about building a new node without a Builder method.



Edit: If anybody cares, I figured it out.

container_node = doc.div always returns the NodeBuilder object that was just used to add a node to your document. NodeBuilders are pretty useless and I have no idea why they are returned; they're an internal Nokogiri class used mainly to set attributes on the new node (so things like foo.div.my_css_class_name work) and setup child blocks (which I guess answers my question.) However, if you do
code:
doc.div {
  container_node = foo.doc.parent
}
Then you'll be able to get the XML::Node that you want. Kinda roundabout and unintuitive, but there you go.

Also, stay away from using XPath and, worse, CSS selectors in Nokogiri if speed is a concern -- they're horrendously slow. I mean, Nokogiri is probably a lot faster than other Ruby alternatives, but still, I literally sped my application up by almost 4x by refactoring the code to walk the DOM manually rather than using selectors. Of course, the trade-off is that the code is a lot more fragile now (if the document structure I'm parsing changes even a bit, it stops working) but it was worth it for me. I used to do 2-3 CSS selects a loop iteration, times 50 iterations per file (on average), times 500 files -- it took 120 seconds; now it takes about 30 sec.

Magicmat fucked around with this message at 13:38 on Feb 16, 2011

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