Skip to content

Commit

Permalink
メソッド名をcurrent_userからauthenticated_userへ変更した
Browse files Browse the repository at this point in the history
  • Loading branch information
baru8 committed Jan 21, 2022
1 parent 1df69f7 commit 4550d29
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 442 deletions.
4 changes: 2 additions & 2 deletions app/controllers/api/v1/analyzes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Api
module V1
class AnalyzesController < BaseController
# before_action :set_analyze, only: %i[show]
before_action :authenticate, except: [:new, :create]
# before_action :authenticate
def new
Analyze.new
end
Expand All @@ -17,6 +17,7 @@ def index
# end

def create

@analyze = current_user.analyzes.new(analyze_params)
if @analyze.save
render json: @analyze, status: :created
Expand All @@ -31,7 +32,6 @@ def analyze_params
params
.require(:analyze)
.permit(:total_points, :alcohol_strongness, :next_motivation, :description, :shuchedule)
.merge(user_id: current_user.id)
end

# def set_analyze
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def authenticate
end
end

def current_user
def authenticated_user
@authenticate
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module Api
module V1
class UsersController < BaseController
def index
users = User.all
render json: users
@users = User.all
render json: @users
end

def create
Expand Down
6 changes: 4 additions & 2 deletions app/frontend/pages/Analyze.vue
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,8 @@ export default {
shuchedule: yourShuchedule,
description: Description,
};
console.log("updateAnalyze")
console.log(updateAnalyze)
resolve(
this.createAnalyze(updateAnalyze)
// this.clearAnswers()
Expand All @@ -571,9 +573,9 @@ export default {
}, 3200);
});
})
.catch(() => {
.catch((e) => {
// エラーハンドリング
console.error('Something wrong!');
console.error(e);
});
return promise;
},
Expand Down
3 changes: 2 additions & 1 deletion app/frontend/pages/ZerokenTop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,13 @@ export default {
},
},
mounted() {
axios.get('/users').then((response) => (this.users = response.data));
this.show = true;
},
async created() {
const a = await this.fetchAuthUser();
console.log("a")
console.log(a)
this.currentUser = a.data.attributes.role;
},
methods: {
Expand Down
14 changes: 8 additions & 6 deletions app/frontend/store/modules/analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ const mutations = {
analyzeArray.push(analyze.shuchedule);
state.analyzes = analyzeArray;
},
updateAnalyze: (state, updateAnalyze) => {
const index = state.analyzes.findIndex((analyze) => analyze.id === updateAnalyze.id);
if (index !== -1) {
state.analyzes.splice(index, 1, updateAnalyze);
}
},
// updateAnalyze: (state, updateAnalyze) => {
// const index = state.analyzes.findIndex((analyze) => analyze.id === updateAnalyze.id);
// if (index !== -1) {
// state.analyzes.splice(index, 1, updateAnalyze);
// }
// },
};

const actions = {
Expand All @@ -44,6 +44,8 @@ const actions = {
try {
const analyzeResponse = await axios.post('analyzes', { analyze: analyze });
commit('addAnalyze', analyzeResponse.data);
console.log("analyzeResponse.data")
console.log(analyzeResponse.data)
return analyzeResponse.data;
} catch (err) {
console.log(err);
Expand Down
Loading

0 comments on commit 4550d29

Please sign in to comment.