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
Pardot
Jul 25, 2001




rugbert posted:

Is something going on with heroku? Im testing an site on it that works fine on my PC but breaks on heroku and heroku logs isnt giving me anything.

Heroku logs is just showing me GET requests instead of errors now

edit - I re pushed and it seems to be working again.

For future problems with is it heroku or is it me, support.heroku.com gets updated almost immediately if there's anything wrong with the platform.

Also speaking of logs, check out expanded logs heroku addons:upgrade logging:expanded, you can --tail them which is really awesome. I think expanded is free for everyone. but you default to basic.

Adbot
ADBOT LOVES YOU

rugbert
Mar 26, 2003
yea, fuck you

Pardot posted:

For future problems with is it heroku or is it me, support.heroku.com gets updated almost immediately if there's anything wrong with the platform.

Also speaking of logs, check out expanded logs heroku addons:upgrade logging:expanded, you can --tail them which is really awesome. I think expanded is free for everyone. but you default to basic.

Awesome thanks, Im not seeing anything for another issue Im having where it takes a minute for my app to load so Im assuming thats normal.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

rugbert posted:

Awesome thanks, Im not seeing anything for another issue Im having where it takes a minute for my app to load so Im assuming thats normal.

Yeah, Heroku doesn't run every app all the time, they're spawned on demand.

hmm yes
Dec 2, 2000
College Slice
Only accounts without an additional dyno spin down. If you have at least one dyno, they always keep the application running and only spawn on demand for the second dyno.

Pardot
Jul 25, 2001




Also, how long it takes to spin up is mostly proportional to the slug size. And they're only spun down if there are no requests in some time period

Pardot fucked around with this message at 22:13 on Dec 8, 2013

rugbert
Mar 26, 2003
yea, fuck you

Pardot posted:

Also, how long it takes to spin up is mostly proportional to the slug size. And they're only spun down if there are no requests in some time period so if you used some sort of uptime monitoring like pingdom or new relic's option, it probably wouldn't get spun down :ssh:

haha awesome.

How would I write my controller to pull all blog posts that were created on or before the current date?

Ive tried a couple things and get nothing, here's what I just tried
code:
@blogs = BlogPost.where(:created_at.to_date > Date.now).order("created_at DESC")
which gives me some error about how "now" is a private method.

jetviper21
Jan 29, 2005

rugbert posted:

haha awesome.

How would I write my controller to pull all blog posts that were created on or before the current date?

Ive tried a couple things and get nothing, here's what I just tried
code:
@blogs = BlogPost.where(:created_at.to_date > Date.now).order("created_at DESC")
which gives me some error about how "now" is a private method.

First thing alway use Time

if you want to stay database agnostic you can do it this way. Note i recommend doing this inside a class method on the model so you can just call arel_table directly. i can provide an example if needed.


Assuming rails 3

code:
arel = StoreItem.arel_table
@blog_posts = BlogPost.where(arel[:created_at].lt(Time.now))
The cleanest solution uses a plugin like: http://metautonomo.us/projects/metawhere/

This is also the easy way and non elegant way.

code:
@blog_posts = BlogPost.where("created_at < ?", Time.now)

skidooer
Aug 6, 2001

rugbert posted:

which gives me some error about how "now" is a private method.
Date.today, Time.now

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

jetviper21 posted:

This is also the easy way and non elegant way.

code:
@blog_posts = BlogPost.where("created_at < ?", Time.now)
Use a named scope, and put it on the model so you can test it.
code:
class BlogPost < ActiveRecord::Base
  scope :before_today, where('created_at < ?', Time.now)
end
And then invoke with:
code:
BlogPost.before_today

skidooer
Aug 6, 2001

BonzoESC posted:

Use a named scope, and put it on the model so you can test it.
Good advice, but you'll want to put that in a lambda, otherwise Time.now will be evaluated when the model loads and will not increment with the clock.
code:
scope :before_today, lambda { where('created_at < ?', Time.now) }

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

skidooer posted:

Good advice, but you'll want to put that in a lambda, otherwise Time.now will be evaluated when the model loads and will not increment with the clock.
code:
scope :before_today, lambda { where('created_at < ?', Time.now) }

Good call, but your tests should cover that :)

hmm yes
Dec 2, 2000
College Slice

skidooer posted:

Good advice, but you'll want to put that in a lambda, otherwise Time.now will be evaluated when the model loads and will not increment with the clock.
code:
scope :before_today, lambda { where('created_at < ?', Time.now) }

This is crazy and also a good post

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
Regarding scopes and where chaining in Rails 3, is there really any significant advantage to using a scope over say:

code:
def self.before_today
  where('created_at < ?', Time.now)
end
It seems a lot cleaner, and avoids some of the issues like evaluating things like Time.now at the point of scope creation.

NotShadowStar
Sep 20, 2000

enki42 posted:

Regarding scopes and where chaining in Rails 3, is there really any significant advantage to using a scope over say:

code:
def self.before_today
  where('created_at < ?', Time.now)
end
It seems a lot cleaner, and avoids some of the issues like evaluating things like Time.now at the point of scope creation.

Nope, and actually you shouldn't be using scopes anyway.

http://www.railway.at/2010/03/09/named-scopes-are-dead/

And according to Aaron Patterson, lambdas are much slower than method calls anyway. (http://confreaks.net/videos/427-rubyconf2010-zomg-why-is-this-code-so-slow) around 28:00.

But everyone should watch the whole thing.

jetviper21
Jan 29, 2005

NotShadowStar posted:

Nope, and actually you shouldn't be using scopes anyway.

I couldn't agree more arel has pretty much killed the need for named scopes

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

NotShadowStar posted:

Nope, and actually you shouldn't be using scopes anyway.

http://www.railway.at/2010/03/09/named-scopes-are-dead/

And according to Aaron Patterson, lambdas are much slower than method calls anyway. (http://confreaks.net/videos/427-rubyconf2010-zomg-why-is-this-code-so-slow) around 28:00.

But everyone should watch the whole thing.

I think that post is based on some allergy to the same-line lambda syntax. That they're still in 3.1, not throwing a deprecation warning, shorter, easier to read, and easier to test is a good indicator that they're still a best practice.

The lambda-vs-method-call thing is a bit of a red herring; the block isn't run for every record in the set, it's run once to build the association. I'd rather lose microbenchmarks and have declarative scopes than the reverse.

plasticbugs
Dec 13, 2006

Special Batman and Robin
I have some routing weirdness going on with my 2-page site. I'm not sure if it's my routes or my controller that is causing the problem.

Here is my controller action:

code:
def create
    @message = Message.new(params[:message])
        
    if @message.save
      flash[:notice] = 'Your message was created!'
      redirect_to :action => "show", :pick_up_code => @message.pick_up_code
    else
      render :action => "new"
    end
 end
and my entire routes file:
code:
Txtapp::Application.routes.draw do
  resources :messages, :only => [:new, :create]
  match '/:pick_up_code' => 'messages#show'
  root :to => "messages#new"
end
Right now, if validation fails on CREATE, the new action is rendered, but the URL in the address bar is
http://mysite.com/messages. And, that doesn't even go anywhere. What's causing that address to pop in there? I'm assuming it's REST, but I don't know how to avoid that and keep the benefits that REST is providing (simplicity).

If validation fails, is there a way to say render the new action as the root URL? If I use 'redirect_to :root' instead of 'render', I'm not able pull the validation errors into the page.

NotShadowStar
Sep 20, 2000
code:
resources :name, :only
Can cause problems if you use Rails' automatic builders like you seem to do, since the builders assume all of the resource routes are available. Just do resources :name. If you don't want certain actions but don't understand where they are coming from, do something like

code:
def update
  raise NotImplementedError
end

def delete
  raise NotImplementedError
end
There when you're playing with your site (more like running tests) and following the generated forms you'll hit errors that you can debug and fix instead of the routes being wonky.

plasticbugs
Dec 13, 2006

Special Batman and Robin

NotShadowStar posted:

code:
resources :name, :only
Can cause problems if you use Rails' automatic builders like you seem to do, since the builders assume all of the resource routes are available. Just do resources :name. If you don't want certain actions but don't understand where they are coming from, do something like

code:
def update
  raise NotImplementedError
end

def delete
  raise NotImplementedError
end
There when you're playing with your site (more like running tests) and following the generated forms you'll hit errors that you can debug and fix instead of the routes being wonky.

I'll try this right now and will report back. Thanks!

EDIT: I ended up leaving the route in there with ":only" but went on to add a route to match the RESTful aberrant route generated by my call to 'render' after a validation fails:
match '/messages' => 'messages#new'

I don't mind this workaround and it keeps my app from breaking. Here's the site by the way: http://www.3dstxt.com

It's basically a messaging site crossed with bit.ly. It's made for users of the Nintendo 3DS, which only supports 16 character messaging. It's one of my first Rails projects.

Thanks for your help!

plasticbugs fucked around with this message at 08:53 on Apr 4, 2011

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

.

Zurich
Jan 5, 2008
I'm trying to convert a number to 'English language' and then pluralize it. I've been Googling/StackOverflowing for the whole day but can't find a solid answer, one that I understand or one that isn't archaic.

At the moment I have 'linguistics' in my gemfile but I can't work out what to do next. I think I might need to create a helper method but that's as far as I can get. Any ideas?

My code in show.html.haml is
code:
%section.remaining
  - if @context.tasks.size == 0
    %h3 Nothing
  - else
    %h3= pluralize(@context.tasks.size, "Task")
  %br
  %span left to do
Works fine like that, outputs '18 Tasks' etc, I just want it to say 'Eighteen Tasks'.



I'm new to this, sorry if it's a silly question.

Zurich fucked around with this message at 15:02 on Apr 5, 2011

smug forum asshole
Jan 15, 2005

Zurich posted:

linguistics

According to this Readme you need to add the language you want this additional functionality to be in somewhere with the linguistics module's `use' method, and that'll give Ruby's core classes access to all of the methods provided by the linguistics module (this looks pretty cool by the way)

So if you put the following in your application_helper.rb (could probably go somewhere else) for instance:
code:
Linguistics::use( :en )
Then you should just be able to use code like this:
code:
 pluralize(@context.tasks.size.en.numwords, "Task")
Give that a shot?

Zurich
Jan 5, 2008

smug forum rear end in a top hat posted:

According to this Readme you need to add the language you want this additional functionality to be in somewhere with the linguistics module's `use' method, and that'll give Ruby's core classes access to all of the methods provided by the linguistics module (this looks pretty cool by the way)

So if you put the following in your application_helper.rb (could probably go somewhere else) for instance:
code:
Linguistics::use( :en )
Then you should just be able to use code like this:
code:
 pluralize(@context.tasks.size.en.numwords, "Task")
Give that a shot?
Nearly :)

Had to add add
code:
require 'linguistics.rb'
to my application_helper.rb as well, and actually download the zip file & move it to my lib/. I guess the Gem didn't work or I'm confused as to how Gems work or something.

Anyway, it's sort of working - pluralize is saying 'one tasks' at the moment, think I might just ditch pluralize and do another if rule to get the suffix right?

Thanks :)

plasticbugs
Dec 13, 2006

Special Batman and Robin
The first Rails site that I've ever put into production is now live at 3dstxt.com. However, my question may not be Rails specific.

Is there an easy Rails Way to prevent Google from indexing certain pages? I'd rather Google didn't crawl my app's "show" pages, where users are posting semi-personal content (email addresses, 3DS Friend Codes, etc).

EDIT for clarity: Because of how the URLs are created, this includes any URL that matches 3dstxt.com/XXXXX

I still would like Google to index the root at 3dstxt.com/ and possibly blog pages or help pages that may eventually exist.

Is robots.txt the only option?

plasticbugs fucked around with this message at 20:47 on Apr 6, 2011

NotShadowStar
Sep 20, 2000
robots.txt in the public directory would be your best bet. Easy, simple, and all the search engines worth a drat respect the directives in it.

By the way, if you did the project as a way to learn Rails, great, but if you wanted something simpler but like the Ruby language Sinatra would likely have been a better fit for a one controller application.

NotShadowStar fucked around with this message at 23:23 on Apr 6, 2011

plasticbugs
Dec 13, 2006

Special Batman and Robin

NotShadowStar posted:

robots.txt in the public directory would be your best bet. Easy, simple, and all the search engines worth a drat respect the directives in it.

By the way, if you did the project as a way to learn Rails, great, but if you wanted something simpler but like the Ruby language Sinatra would likely have been a better fit for a one controller application.

I uploaded a robots.txt just now. Thanks for the help! I started seeing some people sharing their email addresses and Nintendo Friend Codes, and I didn't want Google indexing that stuff. It'd be nice to have some extra free search traffic, but not at the expense of someone's privacy. Hopefully Google will still index my site's root.

As for Sinatra, I considered it - I had built a simple Twitter app using Sinatra and an online tutorial. However, I'm still wrapping my head around VERY basic concepts and tools - git, sessions, routes - so I stuck with Rails.

NotShadowStar
Sep 20, 2000
You can use the Google Webmaster Tools to see how Google is indexing your site, but this is beyond the Rails discussion and belongs in the general web questions thread.

Sharrow
Aug 20, 2007

So... mediocre.
Has anyone played with Torquebox? I was quite happy being long out of the Java world, but I've been reading up on its features and getting messaging/clustering/services through JBoss actually sounds pretty loving tempting. (If it's stable, that is.)

Cock Democracy
Jan 1, 2003

Now that is the finest piece of chilean sea bass I have ever smelled

plasticbugs posted:

The first Rails site that I've ever put into production is now live at 3dstxt.com. However, my question may not be Rails specific.

Is there an easy Rails Way to prevent Google from indexing certain pages? I'd rather Google didn't crawl my app's "show" pages, where users are posting semi-personal content (email addresses, 3DS Friend Codes, etc).

EDIT for clarity: Because of how the URLs are created, this includes any URL that matches 3dstxt.com/XXXXX

I still would like Google to index the root at 3dstxt.com/ and possibly blog pages or help pages that may eventually exist.

Is robots.txt the only option?
If you don't want google to index these pages, consider whether you really want unauthenticated users to see these pages at all.

plasticbugs
Dec 13, 2006

Special Batman and Robin

Cock Democracy posted:

If you don't want google to index these pages, consider whether you really want unauthenticated users to see these pages at all.

These pages are intended to be viewed by total strangers (other Nintendo 3DS owners) who receive a URL that's being broadcasted from the user's Nintendo 3DS. So I can't restrict pages based on authentication.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

plasticbugs posted:

These pages are intended to be viewed by total strangers (other Nintendo 3DS owners) who receive a URL that's being broadcasted from the user's Nintendo 3DS. So I can't restrict pages based on authentication.

Quick google search
Using meta tags to block access to your site

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Is anyone using Pow?

http://pow.cx/

With Pow, there are no preference panes to install. No Apache configuration files to update. And Pow eliminates the need to edit /etc/hosts. To get a Rack app running, just type a single command.

Looks like it's Rails 3 only, though.

8ender
Sep 24, 2003

clown is watching you sleep
pow looked drat cool but I'm only really testing one app at a time right now so I'm still on webrick

rugbert
Mar 26, 2003
yea, fuck you
Im trying to truncate my blog posts (in the index view anyway) so that users have to click on the blog post to see the full post but truncate doesn't seem to play well with html_safe.

Truncate will show images Ive inserted into posts (via tiny mce) but when I have a lot of text it leaves on the first <p> tag which is odd.

NotShadowStar
Sep 20, 2000

Bob Morales posted:

Is anyone using Pow?

http://pow.cx/

With Pow, there are no preference panes to install. No Apache configuration files to update. And Pow eliminates the need to edit /etc/hosts. To get a Rack app running, just type a single command.

Looks like it's Rails 3 only, though.

I still don't understand what the point of this is. The only use-case that I see is 37s has cross-app dependencies, so that makes it easy. Most people don't have this, so the Passenger Preference Pane is just fine.

It mostly just seems like 'hey I can write a Rack adapter in node.js!'

NotShadowStar fucked around with this message at 19:45 on Apr 11, 2011

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

NotShadowStar posted:

I still don't understand what the point of this is. The only use-case that I see is 37s has cross-app dependencies, so that makes it easy. Most people don't have this, so the Passenger Preference Pane is just fine.

I think it's just that making a symlink is less work than firing up the prefpane, waiting for it to restart in 32-bit mode, typing a password, and dragging a folder in.

NotShadowStar
Sep 20, 2000
That's some serious first world problem.

Also 'rails server' is also just fine for development.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

NotShadowStar posted:

That's some serious first world problem.

Also 'rails server' is also just fine for development.

Every problem in software and computing is a first world problem, and "just fine" isn't when "fantastic" is available and free.

Obsurveyor
Jan 10, 2003

Anyone work with plupload and Rails before? When it uploads, rails is throwing an ActionView::MissingTemplate because the :formats is a crazy "text/*" not :html, :js, etc like I have normally seen. I cannot figure out how to make Rails 3 render a template for a specific format instead of always trying to hunt for this crazy one.

When I try something like:
code:
respond_to do |format|
  format.text { render :new }
end
Rails just sends a "406 Not Acceptable", I assume because this insane "text/*" format is not recognized as format.text.

Adbot
ADBOT LOVES YOU

NotShadowStar
Sep 20, 2000
You're trying to solve the problem on the wrong end. You should poke around plupload to see how to get it to not do crazy MIME types.

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