I have a survey form setup on my rails site connected with postgres and deployes with heroku... how can I get the form submissions to show up in my database???? I have made the Question model and setup everything correctly whilst connecting the Heroku and local Postgres databases. For whatever reason I cannot get the data from the form submissions to show up in my database. I have been on this for 2 days please HELP.
Here's my Question Controller class
class QuestionsController < ApplicationController
def show
end
def new
@question = Question.new
end
def create
@question = Question.create(my_params)
render json: @questions.to_json
flash[:success] = "You have successfully submitted"
end
def index
@question = Question.all
render json: @question.to_json
end
def show
@question = Question.find(params[:id])
render json: @question.to_json
end
private
def my_params
params.permit(:Q1, :Q2, :Q3, :Q4, :Q5, :Q6, :Q7, :Q8, :Q9, :Q10, :Q11, :Q12, :name, :age, :location, :background, :gender, :email)
end
end
Here's my routes
resources :questions
get 'home/index'
get 'home/about'
get 'home/terms'
get 'home/mission_statement'
get 'home/values'
get 'home/survey'
get 'home/new'
post 'home/new'
root 'home#index'
end
Here's my form named _survey.html.erb
<%= form_with model: @questions do |form| %>
<h1 style="margin-bottom: 30px"> Survey </h1>
<div class = "form_wrapper">
<%= form.label :Q1, "What is the biggest struggle/problem in your personal life?" %>
<%= form.text_field :Q1, size: "1x1" %>
<%= form.label :Q2, "What’s your biggest struggle/problem on a daily basis at work or in school?" %>
<%= form.text_field :Q2, size: "1x1" %>
<%= form.label :Q3, "When you see something shocking, and record it, where do you share it?" %>
<%= form.select :Q3, [
"",
"Save to camera roll",
"Share with friends + family",
"Share on social media",
"I don't record it" ] %>
<%= form.label :Q4, "How often do you actively seek information about what's going on around you (local events + news)?" %>
<%= form.select :Q4, ["","Daily", "Weekly", "Monthly", "Yearly", "More than Yearly"] %>
<%= form.label :Q5, "Which platforms do you use to seek out this information (TV, social media, websites)?" %>
<%= form.text_field :Q5, size: "1x1" %>
<%= form.label :Q6, "What's an example of a recent event/happening you looked into?" %>
<%= form.text_field :Q6, size: "1x1" %>
<%= form.label :Q7, "Did you share this event with..." %>
<%= form.select :Q7, [
"", "friends", "family", "your social media following", "other"
]%>
<%= form.label :Q8, "If other... please describe" %>
<%= form.text_field :Q8, size: "1x1" %>
<%= form.label :Q9, "How do you stay updated with global events?" %>
<%= form.select :Q9, [
"",
"I do not stay updated with global events",
"Instagram",
"Twitter",
"Snapchat",
"TikTok",
"Facebook",
"Traditional news media (BBC, NBC, FOX)",
"News Apps"
]%>
<%= form.label :Q10, "What would you like to see more of scrolling through your feeds?" %>
<%= form.text_field :Q10, size: "1x1" %>
<%= form.label :Q11, "How much time would you estimate you spend reading or watching videos about the news?" %>
<%= form.select :Q11, [
"",
"Several times a day",
"Once a week",
"A few times a month",
"A few times a year"
]%>
<%= form.label :Q12, "What would make you stay up to date with local and global events more, if anything?" %>
<%= form.text_field :Q12, size: "1x1" %>
Finally, if you don't mind, help us out by letting us know..
</br>
</br>
<%= form.label :name, "Name:" %>
<%= form.text_field :name, size: "1x1" %>
<%= form.label :age, "Age:" %>
<%= form.text_field :age, size: "1x1" %>
<%= form.label :location, "General Area:" %>
<%= form.text_field :location, size: "1x1" %>
<%= form.label :background, "Cultural Background:" %>
<%= form.text_field :background, size: "1x1" %>
<%= form.label :gender, "I'm..." %>
<%= form.select :gender, [
"",
"Female",
"Male",
"Non-Binary",
"Other",
"N/A"
]%>
<div style="font-weight:bold; font-size:22px; text-align:center; color:#f9cd90">
Sign up for a chance to be one of the first to use the product you just helped make even better!
</div>
<%= form.label :email, "Enter your e-mail & we'll let ya know when we launch!" %>
<%= form.email_field :email %>
<%= form.submit "Submit" %>
</div>
<% end %>
Here's my new.html.erb
<body>
<div class = "tab_heading__wrapper">
<div class = "mission_statement font--opensans">
<%= render 'survey' %>
</div>
</div>
</body>
question from:
https://stackoverflow.com/questions/65946141/rails-form-deployed-wont-show-in-postgres