Created
November 27, 2011 22:28
-
-
Save rjfranco/1398301 to your computer and use it in GitHub Desktop.
Pieces of Rails App that is Giving no "name" method error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Post Model | |
class Post < ActiveRecord::Base | |
belongs_to :user | |
validates :title, :presence => true | |
validates :content, :presence => true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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