Generated scaffolding for model via Rails
This commit is contained in:
1 parent
de46fe4065
commit
98e8f446a3
13 files changed
+218
No files matched your search
@@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
@@ -0,0 +1,74 @@
|
||||
class AnswersController < ApplicationController
|
||||
before_action :set_answer, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /answers
|
||||
# GET /answers.json
|
||||
def index
|
||||
@answers = Answer.all
|
||||
end
|
||||
|
||||
# GET /answers/1
|
||||
# GET /answers/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /answers/new
|
||||
def new
|
||||
@answer = Answer.new
|
||||
end
|
||||
|
||||
# GET /answers/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /answers
|
||||
# POST /answers.json
|
||||
def create
|
||||
@answer = Answer.new(answer_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @answer.save
|
||||
format.html { redirect_to @answer, notice: 'Answer was successfully created.' }
|
||||
format.json { render action: 'show', status: :created, location: @answer }
|
||||
else
|
||||
format.html { render action: 'new' }
|
||||
format.json { render json: @answer.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /answers/1
|
||||
# PATCH/PUT /answers/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @answer.update(answer_params)
|
||||
format.html { redirect_to @answer, notice: 'Answer was successfully updated.' }
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { render action: 'edit' }
|
||||
format.json { render json: @answer.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /answers/1
|
||||
# DELETE /answers/1.json
|
||||
def destroy
|
||||
@answer.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to answers_url }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_answer
|
||||
@answer = Answer.find(params[:id])
|
||||
end
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def answer_params
|
||||
params.require(:answer).permit(:response, :question_id)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,2 @@
|
||||
module AnswersHelper
|
||||
end
|
||||
@@ -0,0 +1,25 @@
|
||||
<%= form_for(@answer) do |f| %>
|
||||
<% if @answer.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2><%= pluralize(@answer.errors.count, "error") %> prohibited this answer from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% @answer.errors.full_messages.each do |msg| %>
|
||||
<li><%= msg %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :response %><br>
|
||||
<%= f.text_area :response %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label :question_id %><br>
|
||||
<%= f.text_field :question_id %>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<%= f.submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -0,0 +1,6 @@
|
||||
<h1>Editing answer</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Show', @answer %> |
|
||||
<%= link_to 'Back', answers_path %>
|
||||
@@ -0,0 +1,29 @@
|
||||
<h1>Listing answers</h1>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Response</th>
|
||||
<th>Question</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @answers.each do |answer| %>
|
||||
<tr>
|
||||
<td><%= answer.response %></td>
|
||||
<td><%= answer.question %></td>
|
||||
<td><%= link_to 'Show', answer %></td>
|
||||
<td><%= link_to 'Edit', edit_answer_path(answer) %></td>
|
||||
<td><%= link_to 'Destroy', answer, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
||||
<%= link_to 'New Answer', new_answer_path %>
|
||||
@@ -0,0 +1,4 @@
|
||||
json.array!(@answers) do |answer|
|
||||
json.extract! answer, :id, :response, :question_id
|
||||
json.url answer_url(answer, format: :json)
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
<h1>New answer</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Back', answers_path %>
|
||||
@@ -0,0 +1,14 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<p>
|
||||
<strong>Response:</strong>
|
||||
<%= @answer.response %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Question:</strong>
|
||||
<%= @answer.question %>
|
||||
</p>
|
||||
|
||||
<%= link_to 'Edit', edit_answer_path(@answer) %> |
|
||||
<%= link_to 'Back', answers_path %>
|
||||
@@ -0,0 +1 @@
|
||||
json.extract! @answer, :id, :response, :question_id, :created_at, :updated_at
|
||||
Reference in new issue
Block a user