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
Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.

kayakyakr posted:

I avoid confirmation emails because it kills conversion. Especially when you're trying to get less technical people to follow through. Ugh, the non-technicals.

Exactly. Mandatory registration & confirmation emails are a death sentence in many business areas, like in e-commerce. And that's one area where you need real email address validation, and not a regex like /@/, because invalid email addresses and typos cause a non-trivial amount of support work.

If you guys want a simple way to do it Right™, you can use a service like Mailgun's Email validation API to avoid most of the hard work.

Smol fucked around with this message at 02:00 on Jul 29, 2013

Adbot
ADBOT LOVES YOU

KoRMaK
Jul 31, 2012



Somehow Eclipse just knows where to find the info for content assist.

I'm guessing it uses my rvm gem settings (I'm on windows) to figure out where the gem library is. I'd like to switch this to a different directory which resides on a network drive. Has anyone had experience with this?

Safe and Secure!
Jun 14, 2008

OFFICIAL SA THREAD RUINER
SPRING 2013
I have two models: Thread and Comment. They represent threads and posts in a typical forum - each thread has many comments, each comment belongs to a thread.

I want to have a user create a new Thread by submitting a title for the thread, and some text for the content of the comment. Here is my ThreadController#create method:

code:
  def create
    @thread = MyThread.new(my_thread_params)
    @thread.user = current_user
    @thread.board = Board.find(params[:board_id])

    comment = Comment.new
    comment.content = params[:my_thread][:comment][:content]
    comment.user = @my_thread.user
    comment.my_thread = @my_thread

    if @my_thread.save 
      if comment.save
        redirect_to @my_thread, notice: 'My thread was successfully created.'
      else
        render action: 'new'
      end
    else
      render action: 'new'
    end
  end
Obviously, this is going to give me problems when the board is valid but the comment is invalid - the board will be saved, but the comment will not be saved, so I'll have threads without any posts in them, which is not what I want. What's the non-stupid way to create both a Thread and a Comment?

Sil
Jan 4, 2007
I'm assuming @my_thread is the same as @thread.

code:
   if @my_thread.save 
      if comment.save
        redirect_to @my_thread, notice: 'My thread was successfully created.'
      else
	@my_thread.destroy
        render action: 'new'
      end
    else
      render action: 'new'
    end
As a noob this is the easiest way to do what you want, just wipe the thread row if the comment is invalid. That being said I think a better way to do it would be to require that threads have at least one comment, this way you can ensure that empty threads never save(but you might have parentless comments?).

Maybe you can create the first comment in a before_create filter in the model before you allow it to save a Thread object, but I'm not sure how data passing would work.

e. Might be a dumb question but why not just have a Comment model, with an Original Post column, and some Comments being flagged as OPs(and then treated as if they are threads). Is it ever the case that you want a thread without a comment? You can have objects of class Comment belong to other objects of class Comment unless google lies to me.

Sil fucked around with this message at 07:00 on Jul 31, 2013

tima
Mar 1, 2001

No longer a newbie

Safe and Secure! posted:

I have two models: Thread and Comment. They represent threads and posts in a typical forum - each thread has many comments, each comment belongs to a thread.

I want to have a user create a new Thread by submitting a title for the thread, and some text for the content of the comment. Here is my ThreadController#create method:

code:

  def create
    @thread = MyThread.new(my_thread_params)
    @thread.user = current_user
    @thread.board = Board.find(params[:board_id])

    comment = Comment.new
    comment.content = params[:my_thread][:comment][:content]
    comment.user = @my_thread.user
    comment.my_thread = @my_thread

    if @my_thread.save 
      if comment.save
        redirect_to @my_thread, notice: 'My thread was successfully created.'
      else
        render action: 'new'
      end
    else
      render action: 'new'
    end
  end

Obviously, this is going to give me problems when the board is valid but the comment is invalid - the board will be saved, but the comment will not be saved, so I'll have threads without any posts in them, which is not what I want. What's the non-stupid way to create both a Thread and a Comment?

Without going into the code and the design too far you can always check if my_thread.valid? and comment.valid? Then save both else render new

Safe and Secure!
Jun 14, 2008

OFFICIAL SA THREAD RUINER
SPRING 2013

Sil posted:

e. Might be a dumb question but why not just have a Comment model, with an Original Post column, and some Comments being flagged as OPs(and then treated as if they are threads). Is it ever the case that you want a thread without a comment? You can have objects of class Comment belong to other objects of class Comment unless google lies to me.

I don't really mind Threads not having Comments, but what I'd really like to avoid is Threads not having Comments due their Comments having been invalid at creation time.

As for getting rid of Threads and only having Comments, wouldn't that waste space as I'd then have to add a "title" column to my Comments table, which would be non-null for only a small amount of Comments?

tima posted:

Without going into the code and the design too far you can always check if my_thread.valid? and comment.valid? Then save both else render new

Ugh, I thought .valid? could only be run after one called .save, but rereading the documentation tells me that I'm wrong on that one.

So yeah, as Sil suggested, I'll get rid of the Thread if it's invalid, except I won't even save it in the first, because as you said I can just call valid? first.

Thanks!

Sil
Jan 4, 2007

Safe and Secure! posted:

I don't really mind Threads not having Comments, but what I'd really like to avoid is Threads not having Comments due their Comments having been invalid at creation time.

As for getting rid of Threads and only having Comments, wouldn't that waste space as I'd then have to add a "title" column to my Comments table, which would be non-null for only a small amount of Comments?

Thinking about it some more I think just having Comments would make things more complicated. But I actually have no idea what the space effect would be. Keep in mind the OP would be a boolean column that's essentially 1 byte large(?) but associated with every column. On the other hand the Thread table can get pretty large as well, depending on the average comments/thread your app will have.

I don't really know enough about Rails/SQL/anything to figure out at what comment/thread density one solution is more space efficient than the other. That being said, you might want to allow Threads to be bookmarked and comments not, you might not want to keep discussion flat(ie. can't comment on comments) etc. So there are other concerns to keep in mind if the Thread table is more than just an ID and some child comment pointers.

fake edit. OH but postgresql (and all sql?) can do variable length columns, so your nulls take up no space. See http://stackoverflow.com/questions/5437336/postgres-performance-static-row-length



Initial advice, probably bad. Curious google-journey that it spawned, pretty fun!

manero
Jan 30, 2006

You could also use accepts_nested_attributes_for, and then you don't have to manually build the Comment in your controller.

If you want the Thread to ensure the comment is valid, use "validates_associated :comments" in Thread.

Edit: Then again, validating all the comments of a giant thread is probably not the best idea.

manero fucked around with this message at 14:27 on Jul 31, 2013

kayakyakr
Feb 16, 2004

Kayak is true

manero posted:

Edit: Then again, validating all the comments of a giant thread is probably not the best idea.

But if it's just on thread create, it might not be too bad since there would only be 1 comment to validate.

Sub Par
Jul 18, 2001


Dinosaur Gum
I have a form on which you can post an item, and when you do, I want to handle that post with AJAX and re-render the list of posts. I have my list of posts set up like this:
code:
<div class = "posts" id="feed_entity_<%= f.entity_id %>">
	<%= render @posts.where(:entity_id => f.entity_id) %>
</div>
In create.js.erb though I'm not sure what to enter. My most recent try was this:
code:
$("#feed_entity_<%= params[:post][:entity_id] %>").html("<%= escape_javascript(render partial: 'post') %>");
I've verified that the params are correct and that the right div is being identified by doing .html("foobar") and seeing the correct area of the page replaced with the text "foobar". It's the render part that's tripping me up. I usually have my partials in /shared and I just use basically the same code in html() that I do in the actual .html.erb file. But the construction (which admittedly I copy/pasted from the Hartl tutorial) "render @posts" leaves me not knowing what to do.

Jonny 290
May 5, 2005



[ASK] me about OS/2 Warp
I'm about a two-year Perl dork that is wanting to goof with Ruby/Rails some. My first goal is going to be porting my police-dispatch-page-to-Twitter engine (seen at https://twitter.com/Fayettevillains) to Ruby, piece by piece. There are 3 basic components - the scraper, the geolocator, and the Twitter bit. Figure it should be a good entry project. Any general tips/guidelnies for a guy with terminal Perl Stockholm Syndrome?

EAT THE EGGS RICOLA
May 29, 2008

Jonny 290 posted:

I'm about a two-year Perl dork that is wanting to goof with Ruby/Rails some. My first goal is going to be porting my police-dispatch-page-to-Twitter engine (seen at https://twitter.com/Fayettevillains) to Ruby, piece by piece. There are 3 basic components - the scraper, the geolocator, and the Twitter bit. Figure it should be a good entry project. Any general tips/guidelnies for a guy with terminal Perl Stockholm Syndrome?

I would scrape with nokogiri, geokit is great for geolocation, and there are a bunch of Twitter gems that all work about equally well. I've used this one before.

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.

noob question time: I need to reference a static page in a transactional email, and I need it to reference the instance that is sending the transaction, i.e. my local host, my staging server, or finally production.

My remote coworker has done something to set up routing to the static pages in this manner:

routes:
Ruby code:
  get ':static_page' => 'contents#show', constraints: {static_page: /(about|affiliates|contact|customer-service|merchants|privacy|terms-conditions)/}
and the controller he wrote looks like this:
Ruby code:
class Red::ContentsController < ApplicationController
  layout 'red_layout'

  def show
    @content = request.path.delete('/')
  end

end
I have attempted to add named routes on top of these like so:
Ruby code:
  get '/about' => 'contents#show', :as => :about
but in the email my links just look like this, when I reference for example "about_path":
HTML code:
<a href="http://about" style="color:#999;text-decoration:none" target="_blank">About</a>
Which is obviously hosed. What am I doing wrong here?

edit: derp. the answer is to use *_url instead of *_path. Oh well at least the answer was simple. I've been living in coffeescript la la land for too many weeks.

A MIRACLE fucked around with this message at 17:03 on Aug 2, 2013

Sub Par
Jul 18, 2001


Dinosaur Gum

Sub Par posted:

I have a form on which you can post an item, and when you do, I want to handle that post with AJAX and re-render the list of posts. I have my list of posts set up like this:
code:
<div class = "posts" id="feed_entity_<%= f.entity_id %>">
	<%= render @posts.where(:entity_id => f.entity_id) %>
</div>
In create.js.erb though I'm not sure what to enter. My most recent try was this:
code:
$("#feed_entity_<%= params[:post][:entity_id] %>").html("<%= escape_javascript(render partial: 'post') %>");
I've verified that the params are correct and that the right div is being identified by doing .html("foobar") and seeing the correct area of the page replaced with the text "foobar". It's the render part that's tripping me up. I usually have my partials in /shared and I just use basically the same code in html() that I do in the actual .html.erb file. But the construction (which admittedly I copy/pasted from the Hartl tutorial) "render @posts" leaves me not knowing what to do.

I fixed this when I realized that the @posts instance variable belonged to the User controller and wasn't getting into the Posts controller to be passed to re-render the partial. Added @posts to the Posts controller create method and everything fell into place.

Count Thrashula
Jun 1, 2003

Death is nothing compared to vindication.
Buglord
I have a form page that's supposed to pass true to a boolean DB column when checked and false when unchecked. The problem is, it doesn't pass anything at all! I've tried all of the following (excuse the HAML):

Ruby code:
= form_for(@user) do |f|
...
  = f.checkbox :newsletter
  = f.checkbox :newsletter, checked_value: true
  = f.checkbox :newsletter, checked_value: 1
  = checkbox_tag :user, :newsletter
No matter what I try, when I hit submit, I see the following in the database table:

code:
[#<User ... , newsletter: nil, ... >]
I know that RoR doesn't pass a value when a box is unchecked, but certainly it should pass a value when checked? What am I doing wrong? The "newsletter" column is set to boolean, that's what it should be, right?

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
What does the params hash look like when you send the request? Also, check your attr_accessible settings in the User model or strong_parameters settings in your controller (if you're using it).

(Also, I'm pretty sure that Rails sets a hidden input field as well, so the parameter should be sent even if the checkbox isn't checked.)

Count Thrashula
Jun 1, 2003

Death is nothing compared to vindication.
Buglord

Smol posted:

check your ... strong_parameters

Oh for fucks sake. :negative:

That was it, I didn't have :newsletter in my params.require(:user).permit(...). Why is it always the really stupid, little things? Oh well, thanks for the help :)

Count Thrashula
Jun 1, 2003

Death is nothing compared to vindication.
Buglord
Another question for you guys. I'm playing around with some validation on my signup page - where if they input a username that's too short or a password that doesn't fit the RegEx, they get a little red frowny face in the input box via FontAwesome. I'm having some trouble with jQuery and Rails playing nice together.

/app/views/users/new.html.haml (the gist of the form part) :

HTML code:
<form>
  <fieldset class="smiley-box-username">
    <%= f.text-field :username %>
    <div class="input-validation">
      <i class="icon-frown"></i>
    </div>
  </fieldset>
  <fieldset class="smiley-box-email">
    <%= f.text-field :email %>
    <div class="input-validation">
      <i class="icon-frown"></i>
    </div>
  </fieldset>
...
...
</form>


/app/assets/javascript/smiley_checker.js.coffee :
JavaScript code:
$(document).ready ->
  $(".smiley-box-username").children("input").keyup ->
    filter = /^[a-z][a-z0-9]{6,15}$/i

    if(filter.test(this.value) && $(this).next().children("i").hasClass("icon-frown"))
      $(this).next().children("i").removeClass("icon-frown")
    if(filter.test(this.value) == false && $(this).next().children("i").hasClass("icon-frown") == false)
      $(this).next().children("i").addClass("icon-frown")

  $(".smiley-box-email").children("input").keyup ->
    filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i

    if(filter.test(this.value) && $(this).next().children("i").hasClass("icon-frown"))
    ...
    ...
    ...
...and so on, for each box.

The problem: when I go to the signup page (/signup) directly, it works fine. When I get to it via a "link_to" on my front page, none of the Javascript works. Is there some Ajax thing going on? Should I be using something other than $(document).ready to initialize my script?

Count Thrashula fucked around with this message at 14:33 on Aug 8, 2013

kayakyakr
Feb 16, 2004

Kayak is true

QPZIL posted:

The problem: when I go to the signup page (/signup) directly, it works fine. When I get to it via a "link_to" on my front page, none of the Javascript works. Is there some Ajax thing going on? Should I be using something other than $(document).ready to initialize my script?

It sounds like you're using turbolinks, and you can't use document.ready with that. See: https://github.com/rails/turbolinks/#events

Also, not that it's much different, but I've always preferred to do my on-load as

code:
$(function(){
  ...
});
You can attach a "live" event as

code:
$(document).on('keyup', '.smiley-box-email input', function(){
  ...
});
With the live event handler, you'll be able to load the JS once and have it work everywhere. Add in some prototypal classes for encapsulation and you've got yourself a ujs implementation.

kayakyakr fucked around with this message at 15:30 on Aug 8, 2013

Safe and Secure!
Jun 14, 2008

OFFICIAL SA THREAD RUINER
SPRING 2013
Say I want to handle pagination in a thread on a forum. My first thought is to use query parameters, but I'm under the impression that isn't the Rails way to do things. Am I right? Because it would be so much easier to throw in a query string than setup routes like

threads/:id/:page_number

and then have to avoid using built-in path helpers, since stuff like thread_path(@thread) just routes to threads/:id.

aunt jenkins
Jan 12, 2001

https://github.com/mislav/will_paginate will make all your paginated dreams come true.

Safe and Secure!
Jun 14, 2008

OFFICIAL SA THREAD RUINER
SPRING 2013
Yeah, I'm using that - I'm just taking the :page_number from the URL and handing it to will_paginate. I'm just not sure if I really should be using route parameters for this instead of a query string.

Edit:
Ohhhhh, wowww, I am an idiot. It seems that will_paginate has a view helper of its own, which actually uses adds a query string to your path helper. So I guess query strings aren't frowned upon in rails and all of my work these past hours has been wasted, but aside from undoing it, I won't have several more hours of making it work. :smithicide:

Safe and Secure! fucked around with this message at 05:56 on Aug 9, 2013

kayakyakr
Feb 16, 2004

Kayak is true

Safe and Secure! posted:

Yeah, I'm using that - I'm just taking the :page_number from the URL and handing it to will_paginate. I'm just not sure if I really should be using route parameters for this instead of a query string.

Edit:
Ohhhhh, wowww, I am an idiot. It seems that will_paginate has a view helper of its own, which actually uses adds a query string to your path helper. So I guess query strings aren't frowned upon in rails and all of my work these past hours has been wasted, but aside from undoing it, I won't have several more hours of making it work. :smithicide:

No, query strings aren't frowned upon. You can make "nice" URLs and be happy, but for something like a forum... it's not worth it.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Safe and Secure! posted:

Edit:
Ohhhhh, wowww, I am an idiot. It seems that will_paginate has a view helper of its own, which actually uses adds a query string to your path helper. So I guess query strings aren't frowned upon in rails and all of my work these past hours has been wasted, but aside from undoing it, I won't have several more hours of making it work. :smithicide:
The query string is being added because it couldn't find a suitable route that would consume that parameter.

Re: query strings vs. routes, it comes down to how Tef-compatible you want your routes to be, and if users need to get there with form fields.

yospos.biz/threads/12345/pages/5.html is a separate resource from yospos.biz/threads/12345/pages/6.html , so it's okay that they have different paths; same with yospos.biz/threads/12345/pages/5.json and yospos.biz/threads/12345/pages/6.json (and they better loving have URLs for previous, next, and other referenced resources).

At the same time, though, you're using Rails so you don't have to be autistic about routes. As long as your integration tests say that your poo poo is navigable, you'll be fine.

Deus Rex
Mar 5, 2005

This is a very vain and possibly stupid question, but is there any way to customize the colorization of output from the rails CLI? I really like my terminal color scheme but it's like Solarized in that it fucks with bright colors to make them shades of gray. That means the bright green from the rails CLI (like when it creates a file for instance) are basically unreadable.

MrDoDo
Jun 27, 2004

You better remember quick before we haul your sweet ass down to the precinct.

Deus Rex posted:

This is a very vain and possibly stupid question, but is there any way to customize the colorization of output from the rails CLI? I really like my terminal color scheme but it's like Solarized in that it fucks with bright colors to make them shades of gray. That means the bright green from the rails CLI (like when it creates a file for instance) are basically unreadable.

You could use Pry and then theme it easily with (https://github.com/kyrylo/pry-theme)

EDIT: I would advise using Pry over the standard Rails CLI regardless

Safe and Secure!
Jun 14, 2008

OFFICIAL SA THREAD RUINER
SPRING 2013
Sanity check please:

Edit: Yup, I'm insane, but I just thought of a sane way to do it. Nevermind! That's what I get for coding on a couple hours of asleep after being awake forever. :shepicide:

Safe and Secure! fucked around with this message at 08:12 on Aug 14, 2013

Safe and Secure!
Jun 14, 2008

OFFICIAL SA THREAD RUINER
SPRING 2013
I need to style the markup of my Rails app's views. Can this just be as simple as looking at the bootstrap documentation and then making sure that all my HTML elements have classes from bootstrap, or is there anything I should keep in mind as go through it? I'm using the bootstrap-sass and sass-rails gems, if that changes anything.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Safe and Secure! posted:

I need to style the markup of my Rails app's views. Can this just be as simple as looking at the bootstrap documentation and then making sure that all my HTML elements have classes from bootstrap, or is there anything I should keep in mind as go through it? I'm using the bootstrap-sass and sass-rails gems, if that changes anything.

It certainly can be that simple -- if you use bootstrap you dont have to ever touch a css file. Your views will look good but they will also look pretty generic as bootstrap is becoming fairly ubiquitous. The bootstrap website has a thing that will let you customize the style and then import it into your project, so you can try that. I didn't find it very useful.

If you need something more bespoke, you'll need to get into writing custom css files and using bootstrap mostly as a helper. But if you're starting out, I dont think there's any harm in just bootstrapping everything and then tweaking it from there.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

chumpchous posted:

I dont think there's any harm in just bootstrapping everything and then tweaking it from there.

If you're doing this, you might appreciate the bootstrap-sass gem, which lets you write semantic HTML and style it in Sass or SCSS.

I've been using Zurb Foundation more recently, just because it's nicer to work with in Rails with Sass.

Count Thrashula
Jun 1, 2003

Death is nothing compared to vindication.
Buglord
I'm trying to get into test-driven development since that's The Cool Thing right now (and generally not a bad idea). Is Rspec+Capybara all I really need? Or is there a better system that people are using?

I've looked at Cucumber, but that seems like an unnecessary extra layer if I'm not going to be working with end-users that need to look at my tests. It seems pointless to write out all the descriptions, then define the descriptions, when I could do the same thing with just adding in comments to the testing code.

Cocoa Crispies posted:

If you're doing this, you might appreciate the bootstrap-sass gem, which lets you write semantic HTML and style it in Sass or SCSS.

I've been using Zurb Foundation more recently, just because it's nicer to work with in Rails with Sass.

Is there a big difference between Sass and SCSS? I've been using the terms interchangeably without even realizing they were different.

Also, I generally prefer to have total control over my styling, so I like to use 960 Grid System - all that sweet gridding, none of that extra styling like Foundation or Bootstrap.

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.

The main difference is that SCSS has the braces and semicolons. SCSS is the new hotness mostly because CSS straight up runs as a SCSS conversion. You don't have to change a thing when you swap over from regular CSS. Then you can begin optimizing without trying to make your old stylesheet look like a YAML file.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
rspec and capybara will do the job if you're just getting started. Spork will greatly speed up test startup and run time.

If you use any Ajax/js, definitely consider disabling transactional fixtures and installing the database_cleaner gem. It will save you a lot of headache.

FactoryGirl is really really awesome, I like it so much I started using it in development.

mmachine
Jan 5, 2006
So I'm using a form_for on a model that exists in my application -- that works fine. Create, update, etc. This form is using the multiple select option in Select2, seen here:

http://ivaynberg.github.io/select2/

In this form I'm working on, I'm also trying to include an elastic array of digits that get processed uniquely in my controller. I pass these through via an input like so:

code:
<select multiple id="foo_bar" name="foo_bar[]">
</select>
Within this select element is a series of objects with unique IDs -- that's what I pass to my create and update actions in that controller, which I access like params[:foo_bar] to do my dirty work.

What I noticed happening is that all those IDs post through, but they always sort in numerical order. So if a user selects multiple values -- say 33, 139, 2 and 5 -- I see them posted in the debug logs as 2, 5, 33, 139. However, I need them to pass through in the order the USER entered them, not the way it seems Rails is auto-sorting them as integers.

I have another form that does this similar thing without the order auto-forced, but that uses a form_tag -- not sure if that's the issue or not. That'd make my life a bit harder going that route, but if that's the way to do it I'd be curious to know if anyone's hit something like this before.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

A MIRACLE posted:

The main difference is that SCSS has the braces and semicolons. SCSS is the new hotness mostly because CSS straight up runs as a SCSS conversion. You don't have to change a thing when you swap over from regular CSS. Then you can begin optimizing without trying to make your old stylesheet look like a YAML file.

I usually just use sass-convert: http://rdoc.info/gems/sass/file/README.md#sass-convert , it's less work than artisanal hand-converted Sass files.

mmachine posted:

I have another form that does this similar thing without the order auto-forced, but that uses a form_tag -- not sure if that's the issue or not. That'd make my life a bit harder going that route, but if that's the way to do it I'd be curious to know if anyone's hit something like this before.

What order are they coming in over the wire, before Rails has a chance to mangle it?

DreadCthulhu
Sep 17, 2008

What the fuck is up, Denny's?!
Say you have two models you're exposing as individual resources, say cars and cars_i_own (basically a join table). You often need to know both individually, maybe say to populate a list of all the cars out there, and sometimes to list what cars you actually own.

The most pure implementation would be to just have the client do joins itself after getting those resources. You get all the cars, all the cars you own, join the two lists by id. However you could also expose an additional resource that would do that for you on the server side, almost literally a table join between the two models above, and return that blob to the client.

What are some arguments in favor or against that approach? On one hand you could save on round-trip-times (as in, "give me all ids of cars I own, fetch all cars with these ids. 2 network calls), but on the other now you're on this slippery slope towards creating join resources for every single model in your system. That's a lot of extra crap.

Any thoughts?

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
Keep it simple at first and optimize if it becomes a problem.

DreadCthulhu
Sep 17, 2008

What the fuck is up, Denny's?!

Smol posted:

Keep it simple at first and optimize if it becomes a problem.

Define simple? Simple for whom, for the backend or the client?

kayakyakr
Feb 16, 2004

Kayak is true

DreadCthulhu posted:

Define simple? Simple for whom, for the backend or the client?

For yourself. Also the client, but mostly for yourself.

Adbot
ADBOT LOVES YOU

Fillerbunny
Jul 25, 2002

so confused.

QPZIL posted:

I'm trying to get into test-driven development since that's The Cool Thing right now (and generally not a bad idea). Is Rspec+Capybara all I really need? Or is there a better system that people are using?

I've looked at Cucumber, but that seems like an unnecessary extra layer if I'm not going to be working with end-users that need to look at my tests. It seems pointless to write out all the descriptions, then define the descriptions, when I could do the same thing with just adding in comments to the testing code.

I just came from the ChicagoRuby meetup where a couple guys from Hashrocket gave demos/presentations if how to use Rspec and Cucumber. Obviously they have different applications, especially where Cucumber is geared toward the front end. I'm definitely going to be looking into using it on my next project.

That said, I'm not sure it's an either/or situation with those. They're different tools that accomplish different things. Capybara was shown as one piece of it as well, but was not the focus of either talk.

Edit: I should mention that I was new to all of these tools going into the meetup. I knew about Rspec, but had never actually used it for anything.

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