mobile_on_rails 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mobile_on_rails.rb +20 -49
- data/lib/mobile_on_rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e2854497a208f614144698e8676a783626ee5dc
|
4
|
+
data.tar.gz: a7a650a6a625af0f36430b3a133666b1db12beab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15d91a30c94d709318b728b2d1fa2911effc8901d4ffd1a63fdd9f1bfd280b3bc2971153c53edcd8f02448e7637691f8bad0e56d00491831326ec6a61ff4c3b1
|
7
|
+
data.tar.gz: 2470c314dfd6ed2725fe8839365ff43119af90b98bccc770ba594deaa5f76f4175454a33ba3f440c23e82713725745d312c4dd1f44dd04c8b434468640f6d567
|
data/lib/mobile_on_rails.rb
CHANGED
@@ -29,7 +29,7 @@ module MobileOnRails
|
|
29
29
|
create_table :mor_posts do |t|
|
30
30
|
t.string :title
|
31
31
|
t.text :text
|
32
|
-
t.belongs_to :
|
32
|
+
t.belongs_to :mor_user
|
33
33
|
|
34
34
|
t.timestamps
|
35
35
|
end
|
@@ -65,34 +65,27 @@ end})}
|
|
65
65
|
end})}
|
66
66
|
|
67
67
|
# Create the controller files
|
68
|
-
File.open("#{directory}/app/controllers/
|
69
|
-
'class
|
70
|
-
protect_from_forgery except: :
|
68
|
+
File.open("#{directory}/app/controllers/mor_posts_controller.rb", "w") {|f| f.write(
|
69
|
+
'class MorPostsController < ApplicationController
|
70
|
+
protect_from_forgery except: :create
|
71
71
|
skip_before_filter :verify_authenticity_token
|
72
72
|
respond_to :json
|
73
|
-
|
74
|
-
def
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
when "newpost"
|
80
|
-
save_post(data)
|
81
|
-
when "latest"
|
82
|
-
get_latest(data["count"].to_i)
|
83
|
-
when "edit"
|
84
|
-
edit_post(data)
|
85
|
-
when "delete"
|
86
|
-
delete_post(data)
|
87
|
-
when "all"
|
88
|
-
all_posts
|
89
|
-
else
|
90
|
-
puts "Unrecognized value"
|
91
|
-
end
|
73
|
+
|
74
|
+
def index
|
75
|
+
puts params
|
76
|
+
@all_posts = MorPost.all
|
77
|
+
puts @all_posts.to_json
|
78
|
+
render json: @all_posts
|
92
79
|
end
|
93
|
-
|
94
|
-
def
|
95
|
-
@
|
80
|
+
|
81
|
+
def create
|
82
|
+
@json_data = JSON.parse(JSON.parse(params.keys.to_s).first)
|
83
|
+
@user = MorUser.find_by_user_name(@json_data.values[1])
|
84
|
+
|
85
|
+
@post = MorPost.new
|
86
|
+
@post.user_id = @user.id
|
87
|
+
@post.title = @json_data.values[0]
|
88
|
+
@post.text = @json_data.values[2]
|
96
89
|
if @post.save
|
97
90
|
respond_to do |format|
|
98
91
|
msg = { :status => "ok", :message => "Success!", :html => "<b>...</b>" }
|
@@ -105,28 +98,6 @@ end})}
|
|
105
98
|
end
|
106
99
|
end
|
107
100
|
end
|
108
|
-
|
109
|
-
def edit_post(post)
|
110
|
-
@edit_post = MorPost.find_by(id: post["id"])
|
111
|
-
@edit_post.update(title: post["title"], topics: post"topics"], text: post["text"])
|
112
|
-
end
|
113
|
-
|
114
|
-
def delete_post(post)
|
115
|
-
@delete_post = MorPost.find_by(id: post["id"])
|
116
|
-
@delete_post.destroy
|
117
|
-
end
|
118
|
-
|
119
|
-
def get_latest(count)
|
120
|
-
unless count == 0
|
121
|
-
@all_posts = MorPost.all
|
122
|
-
puts @all_posts.to_json
|
123
|
-
render json: @all_posts
|
124
|
-
else
|
125
|
-
@latest = MorPost.last(count)
|
126
|
-
puts @latest.to_json
|
127
|
-
render json: @latest
|
128
|
-
end
|
129
|
-
end
|
130
101
|
end')}
|
131
102
|
File.open("#{directory}/app/controllers/mor_sessions_controller.rb", "w") {|f| f.write(
|
132
103
|
'class MorSessionsController < ApplicationController
|
@@ -139,7 +110,7 @@ end')}
|
|
139
110
|
|
140
111
|
def create
|
141
112
|
@json_data = decode_json(params)
|
142
|
-
user = MorUser.
|
113
|
+
user = MorUser.find_by_user_name(@json_data["username"])
|
143
114
|
if user && user.authenticate(@json_data["password"])
|
144
115
|
session[:user_id] = user.id
|
145
116
|
respond_to do |format|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobile_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Standridge
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|