I got a new computer, and I finally had the time to sit down and really get Ruby installed and running on my local machine and understand how to get applications set up.
Now I'm getting into the actual programming part of it.
I'm working from
This tutorial which I have been following to the letter. I have my databases set up, and my scaffolding all set.
However, many pages in the application are returning errors such as the following.
In this example, it references a constant "Recipe" that I don't have any idea where it's coming from. (image in spoiler tag)
Anyway, I have been trying to hunt it down by testing other parts of the application that work, and see how far it actually executes until it displays the error, so I know that it can create, edit, and show entries in the database just fine, but for some reason when it has to list all of them it causes that error.
Here is the source for the controller
class RecipesController < ApplicationController
def index
list
render :action => 'list'
end
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
verify :method => :post, :only => [ :destroy, :create, :update ],
:redirect_to => { :action => :list }
def list
@recipes_pages, @recipes = paginate :recipes, :per_page => 10
end
def show
@recipes = Recipes.find(params[:id])
end
def new
@recipes = Recipes.new
end
def create
@recipes = Recipes.new(params[:recipes])
if @recipes.save
flash[:notice] = 'Recipes was successfully created.'
redirect_to :action => 'list'
else
render :action => 'new'
end
end
def edit
@recipes = Recipes.find(params[:id])
end
def update
@recipes = Recipes.find(params[:id])
@recipes.date = Time.now
if @recipes.update_attributes(params[:recipes])
flash[:notice] = 'Recipes was successfully updated.'
redirect_to :action => 'show', :id => @recipes
else
render :action => 'edit'
end
end
def destroy
Recipes.find(params[:id]).destroy
redirect_to :action => 'list'
end
end
@recipes_pages stands out to me as the only oddball among all of the methods, since it's the only one not in all the others (except destroy), but how do I track down the properties of
@recipes_pages?
Furthermore, how did a constant like "Recipe" as opposed to "Recipes" find its way into the program in the first place?
this is a discord of mostly PA people interested in fighting games:
https://discord.gg/DZWa97d5rz
we also talk about other random shit and clown upon each other
Posts
Your best choice would be to make all your model class names singular - "Recipe" instead of "Recipes", since that's how Rails prefers it. Any other way would be fighting against the framework.
EDIT: in case I wasn't clear, look in /app/models, and rename Recipes.rb to Recipe.rb. Edit the file itself, and any associated database schemas, as needed. Then update your controller to call things like "Recipe.find" rather than "Recipes.find".
I was wondering why the fuck the tutorial had you name your database tables in plural but scaffold them in singular... that's definitely a typo on their end.
Thanks, I imagine that will probably solve all of my problems. Didn't know about the de-plurilization.
we also talk about other random shit and clown upon each other
The de-pluralization, as far as I am concerned, makes sense, it just forces you to do things in a certain (good) way. I keep seeing, time and time again, that when given too many options, the programmer will take a bad one and hang themselves with it. Structure rules!
I would also recommend Why's Poignant Guide to Ruby if you want to expand your Ruby brains.
This is the first time I've had the real time to sit down and read/understand the installation procedures and how to use rails to build out the applications. So I'm just happy I was able to get something to submit something to a database, woo.
we also talk about other random shit and clown upon each other
Luckily, you don't have to buy it to read most of it.
And what's cool, it's one of the few books that is written by someone with ADHD for those with any disorder. Not many books can claim that.