THIS IS SPARTA
This commit is contained in:
parent
ef9579594c
commit
daab6ce4f5
|
@ -1,4 +1,26 @@
|
|||
class Ajax::InboxController < ApplicationController
|
||||
def create
|
||||
unless user_signed_in?
|
||||
@status = :noauth
|
||||
@message = "requires authentication"
|
||||
@success = false
|
||||
return
|
||||
end
|
||||
|
||||
question = Question.create!(content: QuestionGenerator.generate,
|
||||
author_is_anonymous: true,
|
||||
author_name: 'justask',
|
||||
user: current_user)
|
||||
|
||||
inbox = Inbox.create!(user: current_user, question_id: question.id, new: true)
|
||||
|
||||
@status = :okay
|
||||
@message = "Successfully added new question."
|
||||
@success = true
|
||||
@render = render_to_string(partial: 'inbox/entry', locals: { i: inbox })
|
||||
inbox.update(new: false)
|
||||
end
|
||||
|
||||
def destroy
|
||||
params.require :id
|
||||
params.require :answer
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
json.partial! 'ajax/shared/status'
|
|
@ -1 +1,2 @@
|
|||
json.partial! 'ajax/shared/status'
|
||||
json.partial! 'ajax/shared/status'
|
||||
json.render @render
|
|
@ -0,0 +1,25 @@
|
|||
.panel.inbox-box{class: "panel-#{i.new? ? 'primary' : 'default'}", data: { id: i.id }}
|
||||
.panel-heading
|
||||
.media
|
||||
- unless i.question.author_is_anonymous
|
||||
%a.pull-left{href: show_user_profile_path(i.question.user.screen_name)}
|
||||
%img.img-rounded.answerbox--img{src: gravatar_url(i.question.user)}
|
||||
.media-body
|
||||
%h6.text-muted.media-heading.answerbox--question-user
|
||||
= user_screen_name i.question.user, i.question.author_is_anonymous
|
||||
asked
|
||||
= time_ago_in_words(i.question.created_at)
|
||||
ago
|
||||
- unless i.question.author_is_anonymous
|
||||
- if i.question.answer_count > 0
|
||||
·
|
||||
%a{href: show_user_question_path(i.question.user.screen_name, i.question.id)}
|
||||
#{i.question.answer_count} response(s)
|
||||
%p.answerbox--question-text= i.question.content
|
||||
.panel-body
|
||||
%textarea.form-control{name: 'ib-answer', data: { id: i.id }}
|
||||
%br/
|
||||
%button.btn.btn-success{name: 'ib-answer', data: { ib_id: i.id }}
|
||||
Answer
|
||||
%button.btn.btn-danger{name: 'ib-destroy', data: { ib_id: i.id }}
|
||||
Delete
|
|
@ -1,31 +1,8 @@
|
|||
.container.j2-page
|
||||
= render 'layouts/messages'
|
||||
- @inbox.each do |i|
|
||||
.panel.inbox-box{class: "panel-#{i.new? ? 'primary' : 'default'}", data: { id: i.id }}
|
||||
.panel-heading
|
||||
.media
|
||||
- unless i.question.author_is_anonymous
|
||||
%a.pull-left{href: show_user_profile_path(i.question.user.screen_name)}
|
||||
%img.img-rounded.answerbox--img{src: gravatar_url(i.question.user)}
|
||||
.media-body
|
||||
%h6.text-muted.media-heading.answerbox--question-user
|
||||
= user_screen_name i.question.user, i.question.author_is_anonymous
|
||||
asked
|
||||
= time_ago_in_words(i.question.created_at)
|
||||
ago
|
||||
- unless i.question.author_is_anonymous
|
||||
- if i.question.answer_count > 0
|
||||
·
|
||||
%a{href: show_user_question_path(i.question.user.screen_name, i.question.id)}
|
||||
#{i.question.answer_count} response(s)
|
||||
%p.answerbox--question-text= i.question.content
|
||||
.panel-body
|
||||
%textarea.form-control{name: 'ib-answer', data: { id: i.id }}
|
||||
%br/
|
||||
%button.btn.btn-success{name: 'ib-answer', data: { ib_id: i.id }}
|
||||
Answer
|
||||
%button.btn.btn-danger{name: 'ib-destroy', data: { ib_id: i.id }}
|
||||
Delete
|
||||
#entries
|
||||
- @inbox.each do |i|
|
||||
= render 'inbox/entry', i: i
|
||||
|
||||
- if @inbox.empty?
|
||||
|
||||
|
|
|
@ -25,10 +25,11 @@ Rails.application.routes.draw do
|
|||
|
||||
match '/settings/profile', to: 'user#edit', via: 'get', as: :edit_user_profile
|
||||
match '/settings/profile', to: 'user#update', via: 'patch', as: :update_user_profile
|
||||
|
||||
|
||||
namespace :ajax do
|
||||
match '/ask', to: 'question#create', via: :post, as: :ask
|
||||
match '/answer', to: 'inbox#destroy', via: :post, as: :answer
|
||||
match '/generate_question', to: 'inbox#create', via: :post, as: :generate_question
|
||||
match '/delete_inbox', to: 'inbox#remove', via: :post, as: :delete_inbox
|
||||
match '/destroy_answer', to: 'answer#destroy', via: :post, as: :destroy_answer
|
||||
match '/create_friend', to: 'friend#create', via: :post, as: :create_friend
|
||||
|
|
Loading…
Reference in New Issue