Skip to content
This repository has been archived by the owner on Jun 22, 2020. It is now read-only.

Commit

Permalink
Rename entry's content attribute to body.
Browse files Browse the repository at this point in the history
Content is kind of a reserved or rather already used word for example
in controller and sometimes can cause issues.
  • Loading branch information
ugisozols committed Mar 25, 2014
1 parent 2cd0b80 commit 2779707
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 22 deletions.
6 changes: 3 additions & 3 deletions app/assets/javascripts/controllers/entries/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ EmberFlare.EntriesNewController = Ember.ObjectController.extend({
fieldsEmpty: function() {
if (this.get("session").get("isAuthenticated")) {
return Ember.isEmpty(this.get("title")) ||
Ember.isEmpty(this.get("content"));
Ember.isEmpty(this.get("body"));
} else {
return Ember.isEmpty(this.get("title")) ||
Ember.isEmpty(this.get("content")) ||
Ember.isEmpty(this.get("body")) ||
Ember.isEmpty(this.get("authorName"));
}
}.property("title", "content", "authorName"),
}.property("title", "body", "authorName"),

actions: {
createEntry: function() {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/models/entry.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
EmberFlare.Entry = DS.Model.extend({
slug: DS.attr("string"),
title: DS.attr("string"),
content: DS.attr("string"),
body: DS.attr("string"),
authorName: DS.attr("string"),
authorGravatarEmailHash: DS.attr("string"),
createdAt: DS.attr("date")
Expand Down
6 changes: 6 additions & 0 deletions app/assets/javascripts/serializers/entry_show.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
EmberFlare.EntrySerializer = DS.ActiveModelSerializer.extend({
normalize: function(type, hash, property) {
hash.id = hash.slug;
return this._super(type, hash, property);
}
});
2 changes: 1 addition & 1 deletion app/assets/javascripts/templates/entries/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</div>
<hr>

<div class="content">{{format-markdown content}}</div>
<div class="body">{{format-markdown body}}</div>
</div>
</div>
{{/each}}
8 changes: 4 additions & 4 deletions app/assets/javascripts/templates/entries/new.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputContent">Content</label>
<label class="control-label" for="inputBody">Body</label>
<div class="controls">
{{textarea value=model.content id="inputContent" placeholder="We only support markdown. Also watch the live preview below as you type"}}
{{textarea value=body id="inputBody" placeholder="We only support markdown. Also watch the live preview below as you type"}}
</div>
</div>
<div class="control-group">
Expand All @@ -36,8 +36,8 @@

<hr>

{{#if model.content}}
{{format-markdown model.content}}
{{#if body}}
{{format-markdown body}}
{{/if}}

{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/templates/entries/show.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
</div>
<hr>

<div class="content">{{format-markdown model.content}}</div>
<div class="body">{{format-markdown body}}</div>
</div>
</div>
4 changes: 2 additions & 2 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ body {
font-family: 'Open Sans', sans-serif;
}

#inputContent {
#inputBody {
width: 95%;
height: 100px;
}
Expand Down Expand Up @@ -64,7 +64,7 @@ textarea:focus, input[type="text"]:focus, input[type="password"]:focus {
color: #8B91A0;
}

.content {
.body {
font-size: 15px;
text-align: justify;
}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/entries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def create
private

def entry_params
permitted_params = params.require(:entry).permit(:title, :content, :author_name)
permitted_params = params.require(:entry).permit(:title, :body, :author_name)

permitted_params.merge! :user_id => current_user.id if current_user

Expand Down
2 changes: 1 addition & 1 deletion app/models/entry.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Entry < ActiveRecord::Base
validates :title, :content, :presence => true
validates :title, :body, :presence => true

belongs_to :user

Expand Down
4 changes: 2 additions & 2 deletions app/serializers/entry_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class EntrySerializer < ActiveModel::Serializer
attributes :id, :slug, :title, :content, :author_name,
:author_gravatar_email_hash, :created_at
attributes :id, :slug, :title, :body, :author_name, :author_gravatar_email_hash,
:created_at

def author_name
user ? user.username : object.author_name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RenameContentToBodyForEntries < ActiveRecord::Migration
def change
rename_column :entries, :content, :body
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140324090316) do
ActiveRecord::Schema.define(version: 20140324134145) do

create_table "entries", force: true do |t|
t.integer "user_id"
t.string "author_name"
t.string "title"
t.text "content"
t.text "body"
t.datetime "created_at"
t.datetime "updated_at"
t.string "slug"
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/entry.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FactoryGirl.define do
factory :entry do
title "Test"
content "Test"
body "Test"
end
end
6 changes: 3 additions & 3 deletions spec/features/entries_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

fill_in :inputAuthor, :with => "Test author"
fill_in :inputTitle, :with => "Testing title"
fill_in :inputContent, :with => "This is a test content"
fill_in :inputBody, :with => "This is a test content"
click_button "Submit"

expect(page).to have_content("Test author")
Expand All @@ -27,7 +27,7 @@
expect(page).to have_no_selector("input[id=inputAuthor]")

fill_in :inputTitle, :with => "Testing title"
fill_in :inputContent, :with => "This is a test content"
fill_in :inputBody, :with => "This is a test content"
click_button "Submit"

expect(page).to have_content("Testing title")
Expand All @@ -37,7 +37,7 @@

scenario "viewing entry" do
entry = FactoryGirl.create(:entry, :title => "Test entry",
:content => "Test content")
:body => "Test content")

visit("/entries")

Expand Down

0 comments on commit 2779707

Please sign in to comment.