Skip to content

Instantly share code, notes, and snippets.

@rjfranco
Created November 27, 2011 22:28
Show Gist options
  • Save rjfranco/1398301 to your computer and use it in GitHub Desktop.
Save rjfranco/1398301 to your computer and use it in GitHub Desktop.
Pieces of Rails App that is Giving no "name" method error
# Post Model
class Post < ActiveRecord::Base
belongs_to :user
validates :title, :presence => true
validates :content, :presence => true
end
# ERB view for show Post
<article>
<header>
<h2><%= @post.title %></h2>
<h3>Post by <%= @post.user.name %></h3>
</header>
<section>
<%= @post.content %>
</section>
</article>
<nav>
<% if user_is_admin? %>
<%= link_to 'Edit', edit_post_path(@post) %>
<%= link_to 'Remove', @post, confirm: 'Are you sure you want to remove this post?', method: :delete %>
<% end %>
<%= link_to 'Back', posts_path %>
</nav>
# User Model (devise)
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable
# Setup accessible (or protected) attributes for your model
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
has_many :posts
def admin?
self.admin
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment