Template missing error in Rails 3 - ruby

Hi i am facing the following error while trying to create a user using Rails 3.
Error:
Template is missing
Missing template admins/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "C:/Site/swargadwar_admin/app/views"
Please check my below code and try to help me to resolve this error.
views/homes/index.html
<div class="container">
<div style="text-align:center;"><img src="/assets/admin.png" style="width:100px; height:120px; " /></div>
<div class="text-div" style="text-align:center;">Swargadwar, Puri Municipality,govt of odisha</div>
<section>
<div id="container_demo" >
<!-- hidden anchor to stop jump http://www.css3create.com/Astuce-Empecher-le-scroll-avec-l-utilisation-de-target#wrap4 -->
<a class="hiddenanchor" id="toregister"></a>
<a class="hiddenanchor" id="tologin"></a>
<div id="wrapper">
<div id="login" class="animate form">
<form action="mysuperscript.php" autocomplete="on">
<h1>Log in</h1>
<p>
<label for="username" class="uname" data-icon="u" > Your email or username </label>
<input id="username" name="username" required type="text" placeholder="myusername or mymail#mail.com"/>
</p>
<p>
<label for="password" class="youpasswd" data-icon="p"> Your password </label>
<input id="password" name="password" required type="password" placeholder="eg. X8df!90EO" />
</p>
<p class="keeplogin">
<input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" />
<label for="loginkeeping">Keep me logged in</label>
</p>
<p class="login button">
<input type="submit" value="Login" />
</p>
<p class="change_link">
Not a member yet ?
Join us
</p>
</form>
</div>
<div id="register" class="animate form">
<%= form_for :admins,:url => {:action => 'create_registration',:controller => "admins" } do |f| %>
<h1> Sign up </h1>
<p>
<label for="usernamesignup" class="uname" data-icon="u">Your username</label>
<%= f.text_field :user_name,placeholder:"mysuperusername690",:id => "usernamesignup" %>
</p>
<p>
<label for="emailsignup" class="youmail" data-icon="e" > Your email</label>
<%= f.email_field :email,placeholder:"mysupermail#mail.com",:id => "emailsignup" %>
</p>
<p>
<label for="passwordsignup" class="youpasswd" data-icon="p">Your password </label>
<%= f.password_field :password,placeholder:"eg. X8df!90EO",:id => "passwordsignup" %>
</p>
<p>
<label for="passwordsignup_confirm" class="youpasswd" data-icon="p">Please confirm your password </label>
<%= f.password_field :password_confirmation,placeholder:"eg. X8df!90EO",:id => "passwordsignup" %>
</p>
<p>
<label for="usernamesignup" class="uname" data-icon="u">Add Image</label>
<%= f.file_field :picture %>
</p>
<p class="signin button">
<%= f.submit "Sign Up"%>
</p>
<p class="change_link">
Already a member ?
Go and log in
</p>
<% end %>
</div>
<div class="error-div">
<% if #admin.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#admin.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% #admin.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
</div>
</div>
</div>
</section>
</div>
controller/admins_controller.rb
class AdminsController < ApplicationController
def create_registration
#admin=Admin.new(params[:admin])
if #admin.save
flash[:notice]="User has created successfully"
flash[:color]="valid"
redirect_to :action => "index" , :controller => "homes"
else
flash[:alert]="User could not created"
flash[:color]="invalid"
render 'index', :controller => "homes"
end
end
end
routes.rb
SwargadwarAdmin::Application.routes.draw do
root :to => "homes#index"
get "homes/index" => "homes#index"
post "admins/create_registration" => "admins#create_registration"
end
controller/homes_controller.rb
class HomesController < ApplicationController
def index
#admin=Admin.new
end
end
Actually i was trying by insert wrong data for checking validation and got this error at this line "render 'index',:controller => 'homes'".Please help me.

Related

Why am i getting an ActiveRecord::AssociationTypeMismatch error while trying to create a form

I'm building a pageantry application form
here are the neccessary codes
the new form
<!--header-->
<div class="header" >
<div class="col-md-3 header-top cbp-spmenu-push">
<nav class="cbp-spmenu cbp-spmenu-vertical cbp-spmenu-left" id="cbp-spmenu-s1">
<li><%= link_to "Home", { controller: "welcome" } %></li>
<li><%= link_to "About us", about_index_path %></li>
</nav>
<!-- /script-nav -->
<div class="main">
<section class="buttonset">
<button id="showLeftPush"><i class="glyphicon glyphicon-menu-hamburger"></i></button>
</section>
</div>
<!-- Classie - class helper functions by #desandro https://github.com/desandro/classie -->
<%= javascript_include_tag 'classie', 'data-turbolinks-track' => true %>
<script>
var menuLeft = document.getElementById( 'cbp-spmenu-s1' ),
showLeftPush = document.getElementById( 'showLeftPush' ),
body = document.body;
showLeftPush.onclick = function() {
classie.toggle( this, 'active' );
classie.toggle( body, 'cbp-spmenu-push-toright' );
classie.toggle( menuLeft, 'cbp-spmenu-open' );
disableOther( 'showLeftPush' );
};
</script>
</div>
<div class="col-md-6 logo">
<h1><span>MISS</span> CRYSTAL <span>NIGERIA</span></h1>
</div>
<div class="clearfix"> </div>
</div>
<!---pop-up-box---->
<%= stylesheet_link_tag 'popuo-box', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'jquery.magnific-popup', 'data-turbolinks-track' => true %>
<!---//pop-up-box---->
<div id="small-dialog" class="mfp-hide">
<div class="search-top">
<div class="login">
<input type="submit" value="">
<input type="text" value="Search.." onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Search..';}">
</div>
<p>Education</p>
</div>
</div>
<script>
$(document).ready(function() {
$('.popup-with-zoom-anim').magnificPopup({
type: 'inline',
fixedContentPos: false,
fixedBgPos: true,
overflowY: 'auto',
closeBtnInside: true,
preloader: false,
midClick: true,
removalDelay: 300,
mainClass: 'my-mfp-zoom-in'
});
});
</script>
<!--//header--><!--banner-->
<div class="head">
<div class="container">
<h2 > Miss Crystal Nigeria / <span>Registration Form</span></h2>
</div>
</div>
<!--content-->
<div class="container">
<div class="page">
<%= form_for #form, html: { multipart: true } do |f| %>
<% if #form and #form.errors and #form.errors.count > 0 %>
<div class="alert alert-danger">
<a class="close" data-dismiss="alert">×<a>
<strong><%= pluralize(#form.errors.count,"error") %> found. Please fill the Important field denoted by the asteriks (*)</strong>
</div>
<% end %>
<div class="grid_3 grid_4">
<div class="page-header">
<h3>Contact Information</h3>
</div>
<div class="bs-example" data-example-id="simple-horizontal-form">
<div class="form-group">
<label class="col-sm-2 control-label">First Name*</label>
<div class="col-sm-6">
<%= f.text_field :first_name, :class => "form-control", :placeholder => "First Name" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Last Name*</label>
<div class="col-sm-6">
<%= f.text_field :last_name, :class => "form-control", :placeholder => "Last Name" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Other Names</label>
<div class="col-sm-6">
<%= f.text_field :other_names, :class => "form-control", :placeholder => "Other Names" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Email*</label>
<div class="col-sm-6">
<%= f.text_field :email_address, :class => "form-control", :placeholder => "Email Address" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Backup Email*</label>
<div class="col-sm-6">
<%= f.text_field :backup_email_address, :class => "form-control", :placeholder => "Backup Email Address" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Address(1)*</label>
<div class="col-sm-6">
<%= f.text_area :first_street_address, :class => "form-control", :placeholder => "First Address" %>
</div>
</div><br /></br /><br />
<div class="form-group">
<label class="col-sm-2 control-label">Address(2)</label>
<div class="col-sm-6">
<%= f.text_area :second_street_address, :class => "form-control", :placeholder => "Second Address" %>
</div>
</div><br /><br /> <br />
<div class="form-group">
<label class="col-sm-2 control-label">Address(3)</label>
<div class="col-sm-6">
<%= f.text_area :third_street_address, :class => "form-control", :placeholder => "Third Address" %>
</div>
</div><br /><br /><br />
<div class="form-group">
<label class="col-sm-2 control-label">City/State/Island*</label>
<div class="col-sm-6">
<%= f.text_field :city, :class => "form-control", :placeholder => "City/State/Island of Residence" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Zip/Postal Code*</label>
<div class="col-sm-6">
<%= f.text_field :postal_code, :class => "form-control", :placeholder => "Zip Code / Postal Code" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Country*</label>
<div class="col-sm-6">
<%= f.country_select :country, priority_countries: ["NG"], :class => "form-control country" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Settlement Area</label>
<div class="col-sm-6">
<%= f.text_field :settlement, :class => "form-control", :placeholder => "Settlement Area of Residence" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Phone(Home)*</label>
<div class="col-sm-6">
<%= f.text_field :phone_home, :class => "form-control", :placeholder => "Home Line" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Phone(Mobile)*</label>
<div class="col-sm-6">
<%= f.text_field :phone_mobile, :class => "form-control", :placeholder => "Mobile Line" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Phone(Work)</label>
<div class="col-sm-6">
<%= f.text_field :phone_work, :class => "form-control", :placeholder => "Work Line" %>
</div>
</div><br />
</div>
<div class="grid_3 grid_4">
<div class="page-header">
<h3>Photos of You</h3>
</div>
<div class="bs-example" data-example-id="simple-horizontal-form">
<div class="form-group">
<label class="col-sm-2 control-label">Photo (1)</label>
<div class="col-sm-4">
<%= f.file_field :image, :class => "submit" %>
</div>
</div><br /><br /><br />
<div class="form-group">
<label class="col-sm-2 control-label">Photo (2)</label>
<div class="col-sm-4">
<%= f.file_field :imaget, :class => "submit" %>
</div>
</div><br />
</div>
<div class="grid_3 grid_4">
<div class="page-header">
<h3>Personal Background and vital Statistics</h3>
</div>
<div class="bs-example" data-example-id="simple-horizontal-form">
<div class="form-group">
<label class="col-sm-2 control-label">How old are you?*</label>
<div class="col-sm-6">
<%= f.number_field :age, :class => "form-control", :placeholder => "Your Age" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Date of birth?*</label>
<div class="col-sm-6">
<%= f.date_select :dob, :class => "form-control", :placeholder => "" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Place of birth?*</label>
<div class="col-sm-6">
<%= f.text_field :place_of_birth, :class => "form-control", :placeholder => "Where were you born?" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">State*</label>
<div class="col-sm-6">
<%= f.text_field :stateoo, :class => "form-control", :placeholder => "What's your state of origin?" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">L. G. A.*</label>
<div class="col-sm-6">
<%= f.text_field :localgovt, :class => "form-control", :placeholder => "What's your Local Government Area" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Height(ft/")*</label>
<div class="col-sm-6">
<%= f.number_field :height, :class => "form-control", :placeholder => "to the nearest whole" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Weight(lbs)*</label>
<div class="col-sm-6">
<%= f.number_field :weight, :class => "form-control", :placeholder => "What do you weigh?" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Swimsuit Size*</label>
<div class="col-sm-6">
<%= f.text_field :swimsuit_size, :class => "form-control", :placeholder => "What's your Swim suit size?" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Dress size*</label>
<div class="col-sm-6">
<%= f.text_field :dress_size, :class => "form-control", :placeholder => "What's your Dress Size?" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Shoe Size*</label>
<div class="col-sm-6">
<%= f.text_field :shoe_size, :class => "form-control", :placeholder => "What's your Shoe Size?" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Employment/School*</label>
<div class="col-sm-6">
<%= f.text_field :employment_school, :class => "form-control", :placeholder => "What's Your Place of Employment or School You Attend?" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Degrees*</label>
<div class="col-sm-6">
<%= f.text_field :degrees, :class => "form-control", :placeholder => "Please list Any Degrees Attained, Scholarships and or Achievements" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Other Awards*</label>
<div class="col-sm-6">
<%= f.text_field :other_awards, :class => "form-control", :placeholder => "List Any Other Awards or Achievements(NON-SCHOLASTIC)" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Family Bio*</label>
<div class="col-sm-6">
<%= f.text_field :family_bio, :class => "form-control", :placeholder => "Tell Us of Any Interesting Fact About Your Family or Their Achievements" %>
</div>
</div><br />
</div>
<div class="grid_3 grid_4">
<div class="page-header">
<h3>More About You</h3>
</div>
<div class="bs-example" data-example-id="simple-horizontal-form">
<div class="form-group">
<label class="col-sm-2 control-label">Facebook Url*</label>
<div class="col-sm-6">
<%= f.text_field :facebook_url, :class => "form-control", :placeholder => "Are You On Facebook? If so, please provide the URL's(links)" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Twitter Url*</label>
<div class="col-sm-6">
<%= f.text_field :twitter_url, :class => "form-control", :placeholder => "Do You Have a Twitter Account? If so, please provide the URL's(links) to your page" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Favourite Color*</label>
<div class="col-sm-6">
<%= f.text_field :fav_color, :class => "form-control", :placeholder => "What's your Favourite Color?" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Favourite Food*</label>
<div class="col-sm-6">
<%= f.text_field :fav_food, :class => "form-control", :placeholder => "What's your Favourite Food?" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Favourite Sport*</label>
<div class="col-sm-6">
<%= f.text_field :fav_sport, :class => "form-control", :placeholder => "What's your Favourite Sport?" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-4 control-label">Have you always lived in Nigeria*</label>
<div class="col-sm-6">
<%= f.check_box :always_naija %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">If No</label>
<div class="col-sm-6">
<%= f.text_field :nalways_naija, :class => "form-control", :placeholder => "Where else have you lived?" %>
</div>
</div><br />
</div>
<div class="grid_3 grid_4">
<div class="page-header">
<h3>Personal Outlook</h3>
</div>
<div class="bs-example" data-example-id="simple-horizontal-form">
<div class="form-group">
<label class="col-sm-2 control-label">Hobbies*</label>
<div class="col-sm-6">
<%= f.text_field :hoobies, :class => "form-control", :placeholder => "What are your Hobbies?" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Sports*</label>
<div class="col-sm-6">
<%= f.text_field :sports, :class => "form-control", :placeholder => "What Sports or Activities Do you Participate in?" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Life Ambition*</label>
<div class="col-sm-6">
<%= f.text_area :life_ambition, :class => "form-control", :placeholder => "What's your Life Ambition?" %>
</div>
</div><br /><br /> <br />
<div class="form-group">
<label class="col-sm-2 control-label">Talent</label>
<div class="col-sm-6">
<%= f.text_field :performable_talent, :class => "form-control", :placeholder => "Do you Have any Performable Talent? If yes, List them" %>
</div>
</div><br /><br /> <br />
<div class="form-group">
<label class="col-sm-2 control-label">Training</label>
<div class="col-sm-6">
<%= f.text_area :special_training, :class => "form-control", :placeholder => "Do you have any special training in Music, Dance, Arts, Etc?" %>
</div>
</div><br /><br /> <br />
<div class="form-group">
<label class="col-sm-2 control-label">Languages*</label>
<div class="col-sm-6">
<%= f.text_area :languages, :class => "form-control", :placeholder => "Please list the languages you speak" %>
</div>
</div><br /> <br /> <br />
<div class="form-group">
<label class="col-sm-2 control-label">Unusual Thing*</label>
<div class="col-sm-6">
<%= f.text_area :most_unusual_thing, :class => "form-control", :placeholder => "Whats's the most thing you have ever done?" %>
</div>
</div><br /><br /> <br />
<div class="form-group">
<label class="col-sm-2 control-label">Proud Moment*</label>
<div class="col-sm-6">
<%= f.text_field :most_proud_moment, :class => "form-control", :placeholder => "Briefly Describe the moment in your life you are most proud of" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-2 control-label">Countries Visited</label>
<div class="col-sm-6">
<%= f.text_field :countries_visited, :class => "form-control", :placeholder => "List all the countries you have travelled to" %>
</div>
</div><br />
</div>
<div class="grid_3 grid_4">
<div class="page-header">
<h3>Personal Statement</h3>
</div>
<div class="bs-example" data-example-id="simple-horizontal-form">
<div class="form-group">
<label class="col-sm-2 control-label">Self Bio*</label>
<div class="col-sm-6">
<%= f.text_area :intresting_selfbio, :class => "form-control", :placeholder => "Tell us something interesting About you." %>
</div>
</div>
</div> <br /><br /><br />
<div class="grid_3 grid_4">
<div class="page-header">
<h3>Verification</h3>
</div>
<div class="bs-example" data-example-id="simple-horizontal-form">
<div class="form-group">
<label class="col-sm-3 control-label">Verify True Information*</label>
<div class="col-sm-6">
<%= f.check_box :true_information %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-3 control-label">Verify True Age*</label>
<div class="col-sm-6">
<%= f.check_box :true_age %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-3 control-label">Terms and Condition*</label>
<div class="col-sm-6">
<%= f.check_box :true_tandc %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-3 control-label">Date*</label>
<div class="col-sm-6">
<%= f.date_select :date %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-3 control-label">Who referred you?*</label>
<div class="col-sm-6">
<%= f.collection_select :referee_id, #referee, :id, :name, :class => "form-control", :prompt => "Who referred you?" %><br />
<%= f.text_field :referee, :class => "form-control", :placeholder => "Someone else? What's his/her name" %>
</div>
</div><br /> <br /><br />
<div class="form-group">
<label class="col-sm-3 control-label">Bank Teller Number*</label>
<div class="col-sm-6">
<%= f.text_field :bank_teller_number, :class => "form-control", :placeholder => "Please input Bank Teller Number or reference or leave blank if free" %>
</div>
</div><br />
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-6">
<%= f.submit :class => "submit" %>
</div>
</div><br />
</div>
</div>
</div></div></div></div></div></div></div></div>
<% end %>
</div>
<!--footter-->
<div class="footer">
<div class="footer-mid">
<div class="container">
<div class="col-sm-4 ft-grid1">
<h3>Location</h3>
<p>Audition Venues are regional</p>
<p>PH / LAGOS / ABUJA / CALABAR / ENUGU</p>
<p>+234 803 229 7343</p>
</div>
<div class="col-sm-4 ft-grid2">
<h3>Follow Us</h3>
<ul class="social-in">
<li><i> </i></li>
<li><i class="twitter"> </i></li>
</ul>
</div>
<div class="col-sm-4 ft-grid1">
<h3>Contact us</h3>
<p>misscrystalnigeriapageant#gmail.com</p>
</div>
<div class="clearfix"> </div>
</div>
</div>
<div class="class-footer">
<div class="container">
<div class="col-md-6 footer-nav">
<ul>
<li ><%= link_to "Home", { controller: "welcome" } %></li>
<li><a href="welcome/about" >About us</a></li>
<li><a href="/admin" >Admin</a></li>
</ul>
</div>
<div class="col-md-6 footer-grid">
<p >© 2016 MissCrystalNigeria. All rights reserved | Design by DicedOrange </p>
</div>
<div class="clearfix"> </div>
</div>
</div>
</div>
<!--//footter -->
the form model
class Form < ActiveRecord::Base
mount_uploader :image, ImageUploader
mount_uploader :imaget, ImageUploader
has_one :referee
end
the form controller
class FormsController < ApplicationController
before_action :set_form, only: [:show, :edit, :update, :destroy]
layout 'aware'
# GET /forms
# GET /forms.json
def index
flash[:notice] = "Access Denied"
redirect_to :controller => 'welcome', :action => 'index', notice: 'Access Denied'
#forms = Form.all
end
# GET /forms/1
# GET /forms/1.json
def show
flash[:notice] = "Access Denied"
redirect_to :controller => 'welcome', :action => 'index', notice: 'Access Denied'
end
# GET /forms/new
def new
#form = Form.new
referees = Referee.all
#referee = referees.order(:name)
end
# GET /forms/1/edit
def edit
flash[:notice] = "Access Denied"
redirect_to :controller => 'welcome', :action => 'index', notice: 'Access Denied'
end
# POST /forms
# POST /forms.json
def create
#form = Form.new(form_params)
respond_to do |format|
if #form.save
flash[:notice] = 'Successfully Submitted Form'
format.html { redirect_to :controller => 'welcome', :action => 'index', notice: 'Form was successfully created.' }
format.json { render :show, status: :created, location: #form }
else
format.html { render :new }
format.json { render json: #form.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /forms/1
# PATCH/PUT /forms/1.json
def update
respond_to do |format|
if #form.update(form_params)
format.html { redirect_to #form, notice: 'Form was successfully updated.' }
format.json { render :show, status: :ok, location: #form }
else
format.html { render :edit }
format.json { render json: #form.errors, status: :unprocessable_entity }
end
end
end
# DELETE /forms/1
# DELETE /forms/1.json
def destroy
#form.destroy
respond_to do |format|
format.html { redirect_to forms_url, notice: 'Form was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_form
#form = Form.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def form_params
params.require(:form).permit(:first_name, :valide, :image, :referee, :localgovt, :stateoo, :imaget, :referee_id, :event_id, :last_name, :other_names, :email_address, :backup_email_address, :first_street_address, :second_street_address, :third_street_address, :city, :postal_code, :country, :settlement, :phone_home, :phone_mobile, :phone_work, :age, :dob, :place_of_birth, :height, :weight, :swimsuit_size, :dress_size, :shoe_size, :employment_school, :degrees, :other_awards, :family_bio, :facebook_url, :twitter_url, :fav_color, :fav_food, :fav_sport, :always_naija, :nalways_naija, :hoobies, :sports, :life_ambition, :performable_talent, :special_training, :languages, :like_to_meet, :most_unusual_thing, :most_proud_moment, :countries_visited, :intresting_selfbio, :true_information, :true_age, :true_tandc, :date)
end
end
the referee model
class Referee < ActiveRecord::Base
has_many :forms
end
the referee controller
class RefereesController < InheritedResources::Base
def index
flash[:notice] = "Access Denied"
redirect_to :controller => 'welcome', :action => 'index', notice: 'Access Denied'
end
def show
flash[:notice] = "Access Denied"
redirect_to :controller => 'welcome', :action => 'index', notice: 'Access Denied'
end
def edit
flash[:notice] = "Access Denied"
redirect_to :controller => 'welcome', :action => 'index', notice: 'Access Denied'
end
private
def referee_params
params.require(:referee).permit(:name, :post)
end
end
anytime i try to create a form, i get this annoying error
ActiveRecord::AssociationTypeMismatch in FormsController#create
Referee(#69872442153920) expected, got String(#69872584329080)
Extracted source (around line #38):
36 # POST /forms.json
37 def create
38 #form = Form.new(form_params)
39
40 respond_to do |format|
41 if #form.save
It looks like you've got two options for inputting a referee: a collection select and text field. So in your form params, you're either submitting a referee ID or just a string of the referee's name. So your Form model is expecting a Referee object, but it's just getting passed a String.
You have a couple options - if an ID is selected, you need to do a Referee.find(params[:referee_id] and pass it to the Form model, along with the other params. Or, if you're submitting the name, you need to create a new Referee and then associate it.
Or you can use a nested form and submit the necessary referee parameters. You'd do something like this within your form:
<%= fields_for :referee do |ff| %>
<%= ff.collection_select :id, #referee, :id, :name, :class => "form-control", :prompt => "Who referred you?" %><br />
<%= ff.text_field :name, :class => "form-control", :placeholder => "Someone else? What's his/her name" %>

Redirect to same page using Rails 3

I need after user's action complete the page should exactly remain same using Rails 3.I am explaining my code and code flow below.
home.html.erb:
<div class="col-md-6" style="float:none; margin:auto;">
<%= form_for :sdf ,:url => {:action => "scan_report" },:html => {:id =>"form-id" } ,remote: true do |f| %>
<% if params[:receipt_no] %>
<div class="input-group bmargindiv1 col-md-12"> <span class="input-group-addon text-left">Receipt No. Scan :</span>
<%= f.text_field :Receipt_No,:class => "form-control", :value => params[:receipt_no],:id => "scan-field",:onfocus => ("$('#rcd_btn').submit()") %>
</div>
<% else %>
<div class="input-group bmargindiv1 col-md-12"> <span class="input-group-addon text-left">Receipt No. Scan :</span>
<%= f.text_field :Receipt_No,:class => "form-control",placeholder:"Receipt No. scan" %>
</div>
<% end %>
<%= f.submit "Submit",:id => "rcd_btn",:style => "display:none;" %>
<% end %>
<div class="clearfix"></div>
</div>
<div class="block block-themed" style="display:none" id="whole-div6" >
<div class="block-title">
<div class="block-options">
<i class="fa fa-arrow-down"></i>
</div>
<h4>Wood Slip</h4>
</div>
<div id="wood-puri">
</div>
</div>
From the above form when user will put the receipt no,lets say 150325006/1 and pressing enter key the below page will display.
_wood.html.erb:
<div class="block-content" style="display:none;">
<div class="timeline-container">
<div class="input-group bmargindiv1 col-md-6 pull-left"><span class="input-group-addon text-left"><div class="leftsidetextwidth">Receipt No :</div></span>
<input type="text" class="form-control" value= "<%= #sdf.Receipt_No %>">
</div>
<div class="input-group bmargindiv1 col-md-6 pull-left"><span class="input-group-addon text-left"><div class="leftsidetextwidth">Date & Time :</div></span>
<input type="text" class="form-control" value= "<%= #sdf.Created_On %>">
</div>
<div class="input-group bmargindiv1 col-md-6 pull-left"><span class="input-group-addon text-left"><div class="leftsidetextwidth">Deceased Name :</div></span>
<input type="text" class="form-control" value= "<%= #hcsy.Deceased_Name %>">
</div>
<div class="input-group bmargindiv1 col-md-6 pull-left"> <span class="input-group-addon text-left"><div class="leftsidetextwidth">Donor Name :</div></span>
<input type="text" class="form-control" value= "<%= #sdf.Doner_Name %>">
</div>
<div class="input-group bmargindiv1 col-md-12 pull-left"> <span class="input-group-addon text-left"><div class="leftsidetextwidth">Amount :</div></span>
<input type="text" class="form-control" value= "<%= #woods.Amount %>">
</div>
<div class="clearfix"></div>
</div>
<div class="block block-themed themed-asphalt">
<div class="block-title"><h5>Office Use</h5></div>
<div class="block-content full">
<%= form_for :vendor,:url => {:action =>"payment" } do |f| %>
<div class="totalaligndiv">
<div class="input-group bmargindiv1 col-md-6" style="margin:auto; float:none;"><span class="input-group-addon text-left"><div class="leftsidetextwidth">Select Vendor :</div></span>
<%= f.select(:v_name,options_for_select(Vendor.where(s_catagory: "Woods").pluck(:v_name),selected: "Select vender name"),{},{:class => "form-control",:prompt => 'Selected Vendor'}) %>
</div>
<div class="totalaligndiv">
<%= f.hidden_field :receipt_no, :value => #sdf.Receipt_No %>
</div>
<div class="totalaligndiv">
<%= f.hidden_field :amount,:value => #woods.Amount %>
</div>
<div class="totalaligndiv">
<%= f.hidden_field :date,:value =>#sdf.Created_On %>
</div>
<div class="clearfix"></div>
<div class="tbpaddingdiv1 text-center">
<%= f.submit "Add to Payment",:class => "btn btn-success" %>
</div>
<div class="clearfix"></div>
</div>
<% end %>
</div>
</div>
</div>
From the above page user will select one vendor name when user will click on submit button the db operation will happen and user will stay on the same page which was displaying before(i.e-user will stay on that _woods.html.erb page also after submit) submit button pressed and the "Add to Payment" vanishes till the next receipt no scan.My controller file is given below.
homes_controller.rb:
class HomesController < ApplicationController
def home
#sdf=TSdf.new
respond_to do |format|
format.html
format.js
end
end
def scan_report
if #sdf=TSdf.find_by_Receipt_No(params[:sdf][:Receipt_No])
#hcsy=THcsy.find_by_Sdp_Id(#sdf.Sdp_Id)
#hcsy_deatils=THcsyDetails.find_by_HCSY_ID(#hcsy.id)
#woods=THcsyFundTypeMaster.find_by_Fund_Type_Code(1)
#burn=THcsyFundTypeMaster.find_by_Fund_Type_Code(2)
#good=THcsyFundTypeMaster.find_by_Fund_Type_Code(3)
#swd=THcsyFundTypeMaster.find_by_Fund_Type_Code(5)
#photo=THcsyFundTypeMaster.find_by_Fund_Type_Code(6)
#vendor=Vendor.new
flash[:notice]=" number matched"
else
splitted = params[:sdf][:Receipt_No].split('/')
receipt = splitted[0]
table_id = splitted[1]
#sdfs=TSdf.find_by_Receipt_No(receipt)
if #sdfs
#hcsys=THcsy.find_by_Sdp_Id(#sdfs.Sdp_Id)
#fund_details=THcsyFundTypeMaster.find_by_Fund_Type_Code(table_id)
else
flash[:notice]="Scan number not found"
end
end
end
def payment
#adds=THcsyFundTypeMaster.find_by_Amount(params[:vendor][:amount])
#vendor=PaymentVendor.create(:Receipt_No => params[:vendor][:receipt_no],:c_date => Date.today.to_time_in_current_zone,:v_date => params[:vendor][:date],:v_amount => params[:vendor][:amount],:v_catagory => #adds.Fund_Type_Name,:v_name => params[:vendor][:v_name],:v_status => "No" )
if #vendor
flash[:notice]="Vendor added the payment"
flash[:color]="valid"
redirect_to :action => "home"
else
flash[:alert]="vendor could not added the payment"
flash[:color]="invalid"
render 'home'
end
end
end
scan_report.js.erb:
<% if #fund_details.Fund_Type_Name=="Woods" %>
$("#whole-div6").css("display", "block");
$("#wood-puri").html("<%= escape_javascript (render 'woods' ) %>");
$("#wood-puri").slideDown(350);
<% end %>
Here inside payment action now i am redirecting home page .But i need user will stay on that rendered _wood.html.erb: page after click on add to payment button.Please help me.
Did you tried :back? i.e. in controller
respond_to do |format|
format.html { redirect_to :back }
end
It will redirect to the page from where request was arrived.

undefined method `errors' for nil:NilClass using RoR

I am getting the following error in my login form when i am trying to attempt by putting the wrong data which should usually shows the login failed message.
Error:
NoMethodError in Sessions#loginadmin
Showing C:/Site/swargadwar_admin/app/views/homes/index.html.erb where line #71 raised:
undefined method `errors' for nil:NilClass
Extracted source (around line #71):
68: <% end %>
69: </div>
70: <div class="error-div">
71: <% if #admin.errors.any? %>
72: <div id="error_explanation">
73: <h2><%= pluralize(#admin.errors.count, "error") %> prohibited this post from being saved:</h2>
74:
Please check my codes below and let me to know where i am doing the mistake.
views/homes/index.html.erb
<div class="container">
<div style="text-align:center;"><img src="/assets/admin.png" style="width:100px; height:120px; " /></div>
<div class="text-div" style="text-align:center;">Swargadwar, Puri Municipality,govt of odisha</div>
<section>
<% if !current_user %>
<div id="container_demo" >
<!-- hidden anchor to stop jump http://www.css3create.com/Astuce-Empecher-le-scroll-avec-l-utilisation-de-target#wrap4 -->
<a class="hiddenanchor" id="toregister"></a>
<a class="hiddenanchor" id="tologin"></a>
<div id="wrapper">
<div id="login" class="animate form">
<%= form_for :admin,:url => {:action =>'loginadmin',:controller => 'sessions' } do |f| %>
<h1>Log in</h1>
<p>
<label for="username" class="uname" data-icon="u" > Your email or username </label>
<%= f.email_field :email,placeholder:"mysupermail#mail.com",:id => "username" %>
</p>
<p>
<label for="password" class="youpasswd" data-icon="p"> Your password </label>
<%= f.password_field :password,placeholder:"eg. X8df!90EO",:id => "password" %>
</p>
<p class="keeplogin">
<%= f.check_box :remember_me,:id => "loginkeeping" %>
<label for="loginkeeping">Keep me logged in</label>
<%= link_to 'Forgetting password ?',admins_forget_path %>
</p>
<p class="login button">
<%= f.submit "Login" %>
</p>
<p class="change_link">
Not a member yet ?
Join us
</p>
<% end %>
</form>
</div>
<div id="register" class="animate form">
<%= form_for :admin,:url => {:action => 'create_registration',:controller => "admins" } do |f| %>
<h1> Sign up </h1>
<p>
<label for="usernamesignup" class="uname" data-icon="u">Your username</label>
<%= f.text_field :user_name,placeholder:"mysuperusername690",:id => "usernamesignup" %>
</p>
<p>
<label for="emailsignup" class="youmail" data-icon="e" > Your email</label>
<%= f.email_field :email,placeholder:"mysupermail#mail.com",:id => "emailsignup" %>
</p>
<p>
<label for="passwordsignup" class="youpasswd" data-icon="p">Your password </label>
<%= f.password_field :password,placeholder:"eg. X8df!90EO",:id => "passwordsignup" %>
</p>
<p>
<label for="passwordsignup_confirm" class="youpasswd" data-icon="p">Please confirm your password </label>
<%= f.password_field :password_confirmation,placeholder:"eg. X8df!90EO",:id => "passwordsignup" %>
</p>
<p>
<label for="usernamesignup" class="uname" data-icon="u">Add Image</label>
<%= f.file_field :picture %>
</p>
<p class="signin button">
<%= f.submit "Sign Up"%>
</p>
<p class="change_link">
Already a member ?
Go and log in
</p>
<% end %>
</div>
<div class="error-div">
<% if #admin.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#admin.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% #admin.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
</div>
</div>
</div>
<% end %>
</section>
</div>
controller/sessions_controller.rb
class SessionsController < ApplicationController
def loginadmin
#admin=Admin.authenticate(params[:admin][:email], params[:admin][:password])
if #admin
session[:user_id]=#admin.id
cookies.signed[:user_id]=#admin.id
params[:admin][:remember_me] == '1' ? remember(#admin) : forget(#admin)
flash[:notice]="Login Successfull"
flash[:color]="valid"
redirect_to :action => "new", :controller => "admins"
else
flash[:notice]="Login Failed"
flash[:color]="invalid"
render 'homes/index'
end
end
def removeuser
session[:user_id] = nil
cookies.delete :user_id
flash[:notice]="user logged out successfully"
flash[:color]="valid"
redirect_to :action => 'index', :controller => 'homes'
end
end
controller/homes_controller.rb
class HomesController < ApplicationController
def index
#admin=Admin.new
end
end
Please help me to resolve this error.
Error is self explanatory.
NoMethodError in Sessions#loginadmin
undefined method `errors' for nil:NilClass
You are getting this error because #admin is nil and you are calling errors method on a nil object..
If you look loginadmin action is sessions controller you are rendering 'index' template when there is no #admin object, which is causing this error.
Fix:
Either create separate templates for both these actions with common code in partials or simply use rails try method which returns nil rather than raising an exception
<% if #admin.try(:errors).try(:any?) %>
OR
Just use a condition at top to separate out error code:
<% if #admin %>
<div class="error-div">
<% if #admin.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#admin.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% #admin.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
</div>
<% end %>
P.S I would recommend you to use different templates with common code separated in partials.

submit action doesnt work in Rails 4

when I submitted the form, the new data don't save in database and as a result I can not see them, but when I make a new data like welcome= Welcome.new and welcome.title="your are" by rails console they work and I can only see things that I have made in console not by application. It seems submit bottom doesnt save any data.
new.html.erb
<h1> Submite </h1>
<form action="new" method="post" class="form-horizontal" role ="form">
<div class="form-group">
<label for"kind"> kind </label>
<input type="string" id="kind" name="kind" class="form-control">
</div>
<br>
<div class="form-group">
<label for"title"> title </label>
<input type="string" id="title" name="title" class="form-control">
</div>
<br>
<div class="form-group">
<label for"text">"text </label>
<input type="text" id="text" name="text" class="form-control">
<br>
</div>
<br>
</div>
<input type="submit" value="Submit" class="btn btn-primary">
List
</div>
index.html.erb
<% #welcomes.each do |welcome| %>
<li><%= welcome.title %> </li>
<% end %>
welcomes_controller
def index
#welcomes = Welcome.all
end
def new
#welcome = Welcome.new
end
def create
#welcome = Welcome.new(user_params)
if #welcome.save
flash.keep[:notice]="Successfuly created"
render :index
else
render :new
# format.json { render json: #user.errors, status: :unprocessable_entity }
end
end
private
def user_params
params.require(:welcome).permit(:kind, :title, :text)
end
Your form is not submitting to the right route. Use form builder instead:
<%= form_for #welcome do |f| %>
<%= f.label :kind %>
<%= f.text_field :kind %>
<%= f.submit %>
<% end %>
This will put right route for form submission into your HTML

Can't generate a form with form helpers

I'm trying to generate a form with an html.erb file, that looks something like this:
<form class="edit-booking" method="post" action="/users/<%= current_user.id %>/accounts/1/bookings/new" data-remote="true">
<header><h1>Edit booking</h1></header>
<input class="booking-name" name="booking[name]" placeholder="Name of the user" type="text" />
<fieldset class="booking-list">
<h2>Booking details</h2>
<ul>
<li>
<input name="booking[name]" type="text" value="Unit name" disabled/>
<input name="booking[check_in]" type="date" value="" />
<input name="booking[check_out]" type="date" value="" />
</li>
</ul>
</fieldset>
<input name="submit" type="submit" value="Save" />
</form>
an I have this ruby code:
<%= form_for [current_user] do |f| %>
<header>
<h1>Edit booking</h1>
</header>
<%= field_set_tag 'Booking details' do %>
<%= f.fields_for :bookings do |booking_form| %>
<%= booking_form.text_field :name, placeholder: "Name" %>
<%= booking_form.text_field :check_in, placeholder: "Check-in" %>
<%= booking_form.text_field :check_out, placeholder: "Check-out" %>
<% end %>
<% end %>
<%= f.submit "Save" %>
<% end %>
But what happens is, it doesn't render anything on the browser even though in the chrome dev tool it shows a form tag.
EDIT:
The html generated is as following:
<form accept-charset="UTF-8" action="/users/1/accounts/1" class="edit_account" id="edit_account_1" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="_method" type="hidden" value="patch"><input name="authenticity_token" type="hidden" value="fzA+hkk3o+itJOI0UDj9F01DuI+A5+zgQ1EVGlwrPww="></div>
<header>
<h1>Edit booking</h1>
</header>
<fieldset><legend>Booking details</legend>
<input id="account_bookings_name" name="account[bookings][name]" placeholder="Name" type="text">
<input id="account_bookings_check_in" name="account[bookings][check_in]" placeholder="Check-in" type="text">
<input id="account_bookings_check_out" name="account[bookings][check_out]" placeholder="Check-out" type="text">
</fieldset>
<input name="commit" type="submit" value="Save">
</form>
My Account model:
class Account < ActiveRecord::Base
belongs_to :user
has_many :products
has_many :bookings
accepts_nested_attributes_for :bookings
accepts_nested_attributes_for :products
end
In your model add:
#Account model
accepts_nested_attributes_for :bookings
Also, should your current_user be an account?

Resources