Skip to content

Instantly share code, notes, and snippets.

class TasksController < ApplicationController
before_filter :authorize
def index
@tasks = Task.all
@users = User.all
end
def new
@task = Task.new
class CompaniesController < ApplicationController
before_filter :authorize, :except => [:new]
def index
@companies = Company.all
end
def new
@company = Company.new
@company.users.build
<%= form_for(@task) do |f| %>
<%= f.label :content, "Task" %>
<%= f.text_field :content%>
<br>
<%= f.label :due_date %>
<%= f.date_select :due_date %>
<br>
<br>
<% if current_page?(new_task_path) %>
<%= f.submit "Create Task", class: "btn btn-large btn-primary" %>
First, here's the full error I'm getting when I try to load the /tasks page:
NoMethodError in Tasks#index
Showing C:/Sites/task_mgr/app/views/tasks/index.html.erb where line #8 raised:
undefined method `name' for nil:NilClass
Extracted source (around line #8):
5: <li>
I changed my table "companies", to "projects" and went through and updated all the references to company/companies. Everything is working fine, except I am again getting that same validation error when I try to create a new task on the projects/4/tasks/new. It's not getting the project_id and therefore the validation is failing. If I hard code the params[:project_id] with the actual number of the project, it creates fine.
I tried all the same things we did yesterday and the day before, to no avail.
**********Here's the error message:
ActiveRecord::RecordInvalid in TasksController#create
Validation failed: Project can't be blank
@nfriend21
nfriend21 / ABILITY.rb
Created September 17, 2012 23:35
cancan ability
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new #guest user
can :manage, :all if user.role == "owner"
if user.role == "employee"
can :read, Company
@nfriend21
nfriend21 / form.erb
Created October 21, 2012 18:11
this is the main script
hello from the view
<form action="/form" method="post">
<input type="text" name="name">
<input type="submit">
</form>
source 'http://rubygems.org'
gem 'sinatra'
gem 'activerecord'
gem 'sinatra-activerecord' # excellent gem that ports ActiveRecord for Sinatra
gem 'thin'
group :development, :test do
gem 'sqlite3'
end
SUITS = %w{clubs hearts spades diamonds}
VALUES = [2, 3, 4, 5, 6, 7, 8, 9, 10, "J", "Q", "K", "A"]
Card = Struct.new(:value, :suit, :amount)
$deck = []
SUITS.each do |suit|
VALUES.each do |value|
SUITS = %w{clubs hearts spades diamonds}
VALUES = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"]
AMOUNTS = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
Card = Struct.new(:value, :suit, :amount)
class Deck < Array
def initialize