Rails 5 No template found error - ruby-on-rails

Error in terminal while running rails s:
Started POST "/users/confirm" for ::1 at 2017-01-28 15:12:30 -0600
Processing by UsersController#confirm as HTML
No template found for UsersController#confirm, rendering head :no_content
It seems that this is actually an Unknown Format error in rails that is passing as a 204 No Content error. I am really new to rails, and doing this for a course.
I have a controller with one def confirm action. It isn't repeated anywhere in my file. Unlike most of the posts previous there isn't a respond_to method located within this action.
Where does the error actually stem from? I don't know if I should be looking at config or re-working the controller
This is my gemfile:
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'rails', '5.0.1'
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development do
gem 'sqlite3'
gem 'pry-rails'
end
group :development, :test do
gem 'rspec-rails', '~> 3.0'
gem 'shoulda'
gem 'rails-controller-testing'
end
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'listen'
gem 'bootstrap-sass'
gem 'bcrypt'
edit.html.erb
<h1>Sign Up Confirmation</h1>`
<div class="row">
<div class='col-md-2'>
<h3>Are you sure these values are correct?</h3>
<h5>Name: <% #user.name %></h5>
<h5>Email: <% #user.email %></h5>
</div>
</div>
<div class="row">
<div class="col-md-2", style="width: auto;">
<%= button_to "Yes", {controller: "users",
action: "create", params: params}, class: 'btn btn-success' %>
</div>
<div class="col-md-2", style="width: auto;">
<%= link_to "No", new_user_path, class: 'btn btn-default' %>
</div>
</div>

It looks like you're missing a confirm.html.erb file in your views/users directory. Rails looks for a view file to render when a action is called, and it's looking for a file with the same name as the action.
If you haven't already, create that file, save and refresh the page. The error should be gone. The page will be blank unless you populate the file with some HTML, but from here you should be good to go.

Related

how to create ruby on rails DB without error in AWS lightsail

i want to create database in ruby on rails.
This worked fine in the development environment.
but upload AWS lightsail, this occurred error.
What's the problem?
below using gem
source 'https://rubygems.org'
gem 'kaminari'
gem 'faker'
gem 'carrierwave'
gem 'fog-aws'
gem 'mini_magick'
gem 'devise'
gem 'sunspot_rails'
gem "bootstrap_form", ">= 4.0.0.alpha1"
gem 'rails', '5.0.6'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'figaro'
gem 'sunspot_solr'
gem 'sqlite3'
group :development, :test do
gem 'byebug'
end
group :development do
gem 'web-console', '~> 2.0'
gem 'spring'
end
below create controller
def create
#person = Person.new(params.require(:person).permit(:name, :phone, :relation, :user_id, :image))
if #person.save
redirect_to people_path
else
redirect_to new_person_path
end
end
below new.html.erb
<body class="main4">
<div class="container" style = "letter-spacing:-1px;">
<center><h2 class="mt-5">연락처 추가</h2></center>
<div style="font-weight: bold; display:flex; justify-content:center; margin-top: 10px; letter-spacing:-1px;">
<%= form_for :person, :html => { :multipart => true, name: "personForm", :onsubmit => "return validateform();"}, url: people_path do |f| %>
<div class="group">
<%= f.file_field :image %>
<span class="highlight"></span><span class="bar"></span>
</div>
<br/>
<div class="group">
<%= f.text_field :name , required: true %>
<span class="highlight"></span><span class="bar"></span>
<label>이름</label>
</div>
<br/>
<div class="group">
<%= f.number_field :phone , required: true %>
<span class="highlight"></span><span class="bar"></span>
<label>전화번호</label>
</div>
<br/>
<div class="group">
<span>관계&nbsp&nbsp&nbsp&nbsp</span>
<%= f.select(:relation, ['가족', '친구', '지인', '직장동료', '거래처', '기타'], {:class => 'form-control'})%>
</div>
<%= f.hidden_field :user_id, value: current_user.id %>
<p style="text-align:right;"><%= f.button :추가, label: '추가', :class => 'btn btn-outline-light' %></p>
<% end %>
</div>
</div>
</div>
<script>
function validateform(){
var personName = document.personForm.person_name;
var personPhone = document.personForm.person_phone;
var personImage = document.personForm.person_image;
if(personName.value==""){
alert("이름이 입력되지 않았습니다.");
document.personForm.person_name.focus();
document.getElementById('person_name').select();
return false;
}
else if(personName.value.length > 4){
alert("이름은 4글자 이하로 작성해주세요.");
document.personForm.person_name.focus();
document.getElementById('person_name').select();
return false;
}
else if(personPhone.value==""){
alert("전화번호가 입력되지 않았습니다.");
document.personForm.person_phone.focus();
document.getElementById('person_phone').select();
return false;
}
}
</script>
</body>
below error scene in lightsail
enter image description here
Again, it works in the development environment, but if you put it on the AWS lightsail, i'm get this error

Dropdown not working on heroku

I am working on my rails app. I have a settings dropdown which works on local host but doesnt work on heroku. Please help me fix this issue. I tried all possible solutions i could find but still not working. I even tried making changes on environment file as well by nothing worked for me.
production.rb
config.assets.compile = true
config.serve_static_assets = true
config.assets.digest = true
_navigation.html.erb
<li class="dropdown">
Settings<b class="caret"></b>
<ul class="dropdown-menu">
<li><%= link_to "Change password", changepassword_path %></li>
<% if current_user.superadmin? %>
<li>Manage Users</li>
<li>General Settings
</li>
<% end %>
</ul>
</li>
<% end %>
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Freetoplay</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= render 'layouts/navigation' %>
<div class="bd">
<div class="container">
<div class="row">
<div class="col-lg-12 col-sm-12 col-xs-12">
<ol class="breadcrumb">
<%= render_breadcrumbs :separator => " / " %>
</ol>
</div>
</div>
</div>
</div>
<%= render 'layouts/messages' %>
<div class="container">
<%= yield %>
</div>
<%= render 'layouts/footer' %>
</body>
</html>
gem file
gem 'rails', '~> 5.2.0'
gem 'bootstrap-datepicker-rails'
gem 'bcrypt', '~> 3.1.7'
gem 'cocoon'
gem 'webpacker', '~> 3.5.5'
gem 'puma', '~> 3.11'
gem "paperclip", "~> 6.0.0"
gem 'bootstrap-sass', '~> 3.3.7'
gem 'jquery-rails'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'will_paginate', '3.1.5'
gem 'bootstrap-will_paginate', '1.0.0'
gem "breadcrumbs_on_rails"
gem "wysiwyg-rails"
gem "font-awesome-rails"
gem 'filterrific'
gem 'coffee-rails', '~> 4.2'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'sqlite3'
end
group :production do
gem 'pg'
end
group :development do
gem 'pry'
gem 'pry-nav'
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15', '< 4.0'
gem 'selenium-webdriver'
gem 'chromedriver-helper'
end
I don't know if this will help you, but I always run these commands to update my css for Heroku.
RAILS_ENV=production bundle exec rake assets:precompile
git add public/assets
git commit -m "vendor compiled assets"
git push heroku master

Rails/devise app not working properly on Heroku due to new_user_registration_path

Hope one of you can help me out on this one, since I've been breaking my head on it for a while.
I deployed my app to Heroku after trying it out on the cloud9 preview.
The problem is that whenever I try to press the button to create a account for a paid subscription, I don't get linked to the page to fill in my credentials. However, on cloud9 this seems to be working fine.
I found the the sole difference between the two by hovering over the same buttons on the different platforms with my mouse.
On cloud9 I get: https://xxxxxxxx-xxxxx.xxxxxxx.xx/users/sign_up?plan=1
On Heroku I get: https://xxxxxxxx-xxxx-xxxxx.herokuapp.com/sign_up
So whenever I click the one on Heroku, I get my build-in flash message saying: Please select a membership plan to sign up!
To be more specific whereas the problem lies according to me, I think it's somewhere in the home.html.erb where the variable gets passed through. (added below)
So it seems that the routing isn't working correct on my Heroku, but I just can't figure out why. I've added my files below.
Hope someone can help me out on this one!
Kind regards.
Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', group: [:development, :test]
# Use postgresql as the database for production
group :production do
gem 'pg'
gem 'rails_12factor'
end
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
### ADDED GEMS ###
# Bootstrap Gem
gem 'bootstrap-sass', '~> 3.3.6'
# Devise Gem
gem 'devise'
# Font Awesome
gem 'font-awesome-rails'
# Use stripe for handling payments
gem 'stripe'
# Use figaro to hide secret keys
gem 'figaro'
ruby '2.3.0'
routes.rb
Rails.application.routes.draw do
devise_for :users, controllers: { registrations: 'users/registrations' }
resources :users do
resource :profile
end
resources :contacts
get '/about' => 'pages#about'
root 'pages#home'
end
pages_controller.rb
class PagesController < ApplicationController
def home
#trial_plan = Plan.find_by id: '1'
#pro_plan = Plan.find_by id: '2'
end
def about
end
end
users/registrations_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
before_filter :select_plan, only: :new
def create
super do |resource|
if params[:plan]
resource.plan_id = params[:plan]
if resource.plan_id == 2
resource.save_with_payment
else
resource.save
end
end
end
end
private
def select_plan
unless params[:plan] && (params[:plan] == '1' || params[:plan] == '2')
flash[:notice] = "Please select a membership plan to sign up."
redirect_to root_url
end
end
end
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Ayris</title>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag "https://js.stripe.com/v2/", type: 'text/javascript' %>
<%= javascript_include_tag 'application' %>
<%= tag :meta, :name => "stripe-key", :content => STRIPE_PUBLIC_KEY %>
<%= csrf_meta_tags %>
</head>
<body>
...
<%= link_to root_path, class: 'navbar-brand' do %>
<i class="fa fa-users"></i>
Ayris
<% end %>
...
<% if user_signed_in? %>
...
<% else %>
...
<% if user_signed_in? %>
...
<% end %>
<li><%= link_to "About", about_path %></li>
<li><%= link_to "Contact Us", new_contact_path %></li>
</ul>
</div><!-- /.navbar-collapse -->
</div>
</nav>
<div class="container">
<% flash.each do |key, value| %>
<%= content_tag :div, value, class: "alert alert-#{key}" %>
<% end %>
<%= yield %>
</div>
</body>
</html>
home.html.erb
<% if user_signed_in? %>
...
<% if current_user.profile %>
...
<% else %>
...
<% end %>
...
<% else %>
<div class="col-md-6">
<div class="well">
<h2 class="text-center">Trial Membership</h2>
<h4>Sign up for free and get trial access for a period of 10 days.</h4>
<br/>
<%= link_to "Sign up for Trial", new_user_registration_path(plan: #trial_plan), class: 'btn btn-primary btn-lg btn-block' %>
</div>
</div>
<div class="col-md-6">
<div class="well">
<h2 class="text-center">Pro Membership</h2>
<h4>Sign up for the pro account for €75/month and get access to all functions.</h4>
<%= link_to "Sign up for Pro", new_user_registration_path(plan: #pro_plan), class: 'btn btn-success btn-lg btn-block' %>
</div>
</div>
<% end %>
</div>
I fixed the problem, the thing you've mentioned about the database was right. The problem was that, for some reason, the db migration to Heroku was unsuccessful, without giving me any notice about it. After running:
Heroku run rails c
Plan.create(name: 'trial', price: 0)
Plan.create(name: 'pro', price: 75)
After running these commands the both plans were injected to the database of my Heroku app. My code seems to work perfectly fine now, altough I've changed the following piece of code according to your comment about hardcoding ID's
pages_controller.rb
class PagesController < ApplicationController
def home
if Plan.find_by name: 'trial'
#trial_plan = 1
end
if Plan.find_by name: 'pro'
#pro_plan = 2
end
end
end
Thanks for the heads up.

Simple form not adding bootstrap classes

I've created a new Rails project, added gem 'simple_form', '~> 3.2', '>= 3.2.1' to my gemfile and configured my project to use Bower, than added Bootstrap via Bower.
Even though I used rails generate simple_form:install --bootstrap, the form elements don't get the Bootstrap css classes.
I've checked the HTML after the page is rendered and the Bootstrap css/js are there. Do I need to use Bootstrap gem instead of Bower package??
Here is the .bowerrc file:
{
"directory": "vendor/assets/components"
}
bower.json
{
"name": "TesteKlipbox",
"authors": [
"Juliano Nunes"
],
"description": "",
"main": "",
"license": "MIT",
"homepage": "",
"private": true,
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"vendor/assets/components",
"test",
"tests"
],
"dependencies": {
"bootstrap": "^3.3.6"
}
}
Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.15'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'simple_form', '~> 3.2', '>= 3.2.1'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
And the form code:
<%= simple_form_for(#noticia, html: { class: 'form-horizontal' }) do |f| %>
<% if #noticia.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#noticia.errors.count, "error") %> erros impediram que esta notícia fosse salva:</h2>
<ul>
<% #noticia.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :titulo %><br>
<%= f.text_field :titulo %>
</div>
<div class="field">
<%= f.label :texto %><br>
<%= f.text_area :texto %>
</div>
<div class="field">
<%= f.label :data %><br>
<%= f.datetime_select :data %>
</div>
<div class="field">
<%= f.label :tags %><br>
<%= f.text_field :tags %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
UPDATE
Another user has already answered the question. My mistake was that I didn't replace f.text_field by f.input. It has nothing to do with the suggested bootstrap theme question.
To start using Simple Form you just have to use the helper it
provides:
<%= simple_form_for #user do |f| %>
<%= f.input :username %>
<%= f.input :password %>
<%= f.button :submit %>
<% end %>
The helper being f.input instead of the Rails helper(s) such as f.text_field, f.text_area etc. See Simple_Form Usage and Rails Form Helpers.
The below image shows the first input using f.text_field and the second using f.input.
Make sure that bootstrap is stored in the correct location:
bootstrap.min.css as well as bootstrap.css,
bootstrap.min.js and bootstrap.js,
all need to be located in app/assets/stylesheets and app/assets/javascripts respectively.
Add *= require bootstrap to app/assets/stylesheets/application.css and,
add //= require bootstrap to app/assets/javascripts/application.js

Twitter bootstrap issue using Ruby on Rails

Can anybody please solve me one issue regarding bootstrap using in ROR.
Issue:
I have integrated gem "'bootstrap-sass', '3.2.0.2'" in my gem file.After adding some bootstrap navigation code in application.html.erb,it is showing one nice bootstrap navigation bar.If i am doing some changes in style sheet and refreshes the page it is splitting means the nav menu lists is not coming in inline and next time onward it is repeating.Actually i want the original nav bootstrap bar even if I did any changes in style sheet.
Please check my below code snippets and make it correct.
My codes are as follows:
Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.19'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
gem 'bootstrap-sass', '3.2.0.2'
homes.css.scss
#import "bootstrap-sprockets";
#import "bootstrap";
body {
padding-top: 60px;
}
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>LibraryManagement</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<header class="navbar navbar-fixed-top navbar-default">
<div class="container">
<%= link_to "Library Management System", '#', id: "logo" %>
<nav>
<ul class="nav navbar-nav navbar-right">
<li><%= link_to "Home", '#' %></li>
<li><%= link_to "Books", '#' %></li>
<li><%= link_to "Member Entry", '#' %></li>
<li><%= link_to "Admin Login", '#' %></li>
</ul>
</nav>
</div>
</header>
<div class="container">
<%= yield %>
</div>
</body>
</html>
homes/index.html.erb
<h1>Index page</h1>
Please help me.Thanks in advance.

Resources