Skip to content

Instantly share code, notes, and snippets.

@katiebuilds
Created March 10, 2015 13:09
Show Gist options
  • Save katiebuilds/0610e803b3de32ef25b9 to your computer and use it in GitHub Desktop.
Save katiebuilds/0610e803b3de32ef25b9 to your computer and use it in GitHub Desktop.
Detailed Rails Questions
What is the difference between form_for and form_tag?
Form_for is for an object...if you are collecting data in fields that that particular object has in its database. Form_tag is just for a regular form.
What is the difference between render and redirect_to?
Render displays a page or a form. Redirect_to takes you to another page.
What is the difference between development and production?
Development is the environment that you are working in. Production is the environment that you deploy to when the app is ready to be used. Often, some of your gems will have to be different depending on what environment you are in.
Big Picture Questions
What do you think about RSpec and MiniTest? Have you used either of them? Which do you think is better?
I have used MiniTest. From what I have heard about RSpec, people seem to like it, because it is very readable. MiniTest works well for my purposes, but RSPec probably is more powerful in terms of what it can do.
What do you try to keep in mind when you're designing your models?
I try to use the models to handle most of the logic, so that there is not a lot going on in the controller.
@katiebuilds
Copy link
Author

form_for @potato some object, in an instance variable, often user. nested attributes...if a user has_many educations.... name field

f.fields for ff
school
degree

school
degree

not on the user, but on an associated table...accepts_nested_attributes_for
form_for goes to create or update...create if it hasn't already been saved, update if it has
f.text_field

params[:user][:name] nested in a sub hash...a form for that user

form_tag...not for an object. when you submit it, it goes back to the exact same page...posts to the page
params[:name]
text_field_tag no f.
where the form is showing up. in the controller...def action @potato = Blah.new
if request.post? (also need a git) request is always present in controllers...contains all the information that the users submitted...it has the path, the headers, the HTML verb, and so on. then save, or update. orrr immediately give it a path to submit to

&&&&
when you redirect to new, the new action code runs use flash for a redirect
when you render new, the new code doesn't run flash.now for a render

&&&&
pry, byebug--devel
bourbon--both
puma--production

&&&&
development, local, on your computer usually
production, out there, on a server somewhere
test is a different environment...not part of development

&&&&
ruby vs. rails...testing is a little different, but all minitest. rspec is more robust?? actually equal as far as capabilities. minitest is built in. contentious...religious debate minitest runs faster. rspec can do behavior-driven development. syntax of rspec...maybe clearer. can use capybara with either. just don't get heated about it...either one is fine...

if you have no clue, ask for details, be curious, don't fake it. don't just be like, haven't heard of it, next. otherwise say what you know.

&&&&
also, related to data tables...figure out which tables vs. text fields you need
extra models that don't correlate 1:1 with database, don't inherit from ActiveRecord base. the logic of a model should only pertain to what it is...as few dependencies on other models as possible. between models, use a method that can be easily called single responsibility principle...each thing in your code does one thing, try to stick to 1 mayyybe 2 parameters if your method has 10 parameters, you missed some. students: break it out into objects: courses, students transcripts then a user, can encompass a lot of things but you can pass it around as one parameter

form for doesn't need to know that there's a database behind it, needs an object, but makes a lot of assumptions....for an object that is a dog, checks to see if it's persisted? saved in the database or not, so the object has to respond to that. then form_for assumes there's a dogs controller with a create and update action...whether or not those things are saved to the database is up to you. if they don't go to the database, they go....somewhere. put it in a place where it persists...not just memory. (michael says api???) could write classes that read and write csv, excel files, images. probbbbably will be a database.

everything is an object.
"Mason"
:today
2
true.class => TrueClass

String is a class. to get objects out, .new. String.class => Class
classes are objects. classes are instances of the class class.

String.superclass = class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment