I have 1 form which use dropzone gem, what i am trying to achieve is
i want to upload my image inside a form which have 1 to many relationship, i've been struggle to make it work with no luck.
here is my database structure :
apartement:
id
name
desc
unitplan:
id
unitplanphoto
apartement_id
an apartement has many unit plans, instead an unit plan only belong to 1 apartement,
<div class="container-fluid">
<div class="animated fadeIn">
<!--/.row-->
<div class="row">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<strong>Apartement Form</strong>
</div>
<%= form_for #apt, html: {class: "form-horizontal", :multipart=>true} do |f| %>
<div class="card-block">
<div class="form-group row">
<%= f.label 'Apartement Name', class: 'col-md-4 form-control-label' %>
<div class="col-md-8">
<%= f.text_field :apt_name, class: "form-control" %>
</div>
</div>
<div class="form-group row">
<%= f.label 'Apartement Address', class: 'col-md-4 form-control-label' %>
<div class="col-md-8">
<%= f.text_area :apt_address, rows: 5, cols: 46 , class: "form-control" %>
</div>
</div>
<div class="form-group row">
<%= f.label 'Latitude', class: 'col-md-4 form-control-label' %>
<div class="col-md-8">
<%= f.text_field :apt_lat, class: "form-control" %>
</div>
</div>
<div class="form-group row">
<%= f.label 'Longtitude', class: 'col-md-4 form-control-label' %>
<div class="col-md-8">
<%= f.text_field :apt_long, class: "form-control" %>
</div>
</div>
<div class="form-group row">
<%= f.label 'Thumbnail', class: 'col-md-4 form-control-label' %>
<div class="col-md-8">
<%= f.file_field :thumbnail, accept: 'image/jpeg,image/gif,image/png' %>
</div>
</div>
<div class="form-group row">
<%= f.label 'Appartement Description', class: 'col-md-4 form-control-label' %>
<div class="col-md-8">
<%= f.text_area :apt_desc, rows: 5, cols: 46 , class: "form-control" %>
</div>
</div>
<div class="form-group row">
<%= f.label 'Developer', class: 'col-md-4 form-control-label' %>
<div class="col-md-8">
<%= collection_select(:apt, :developer_id, #developers, :id, :devname, {:prompt => false}, class: "form-control") %>
</div>
</div>
<div class="form-group row">
<%= f.label 'Area', class: 'col-md-4 form-control-label' %>
<div class="col-md-8">
<%= collection_select(:apt, :area_id, #areas, :id, :area_desc, {:prompt => false}, class: "form-control") %>
</div>
</div>
<div class="form-group row">
<%= f.label 'Status', class: 'col-md-4 form-control-label' %>
<div class="col-md-8">
<%= f.select :apt_status, options_for_select(#apt_statuses.collect { |s| [s[0].humanize, s[0]] }, selected: #apt.apt_status), {} , class: "form-control" %>
</div>
</div>
<div class="form-group row">
<%= f.label 'Facility', class: 'col-md-4 form-control-label' %>
<div class="col-md-8">
<%= collection_check_boxes(:apt, :facility_ids, #facilities, :id, :facility_desc) %>
</div>
</div>
<div class="form-group row">
<%= f.label 'Point of Interest', class: 'col-md-4 form-control-label' %>
<div class="col-md-8">
<%= collection_check_boxes(:apt, :poi_ids, #pois, :id, :poi_name) %>
</div>
</div>
<div class="form-group row">
<%= f.label 'Floor plan photos', class: 'col-md-4 form-control-label' %>
<div class="col-md-8">
<%= file_field_tag "images[]", type: :file, multiple: true %>
</div>
</div>
<% end %>
<div class="form-group row">
<div class="col-md-8">
<input id="unitplans_ids" name="unitplans_ids" type="hidden" value="">
<!--<input data-url="/photos" id="unitplans_upload" multiple="multiple" name="unitplans[]" type="file" ></input>-->
<!--<form action="/unitplans/create" id="dzCover" method="post" enctype="multipart/form-data" class="dropzone">-->
<%= form_for #unitplan, html: {class: "dropzone", :multipart=>true, id: "dzCover"} do |f| %>
<div id="actionsCover" class="row">
<div class="col-lg-8">
<label for="image">Unit plan photos : </label>
<!-- The fileinput-button span is used to style the file input field as button -->
<span class="btn btn-success fileinput-button2">
<i class="glyphicon glyphicon-plus"></i>
<span>Add files...</span>
</span>
<button type="button" class="btn btn-primary start">
<i class="glyphicon glyphicon-upload"></i>
<span>Start upload</span>
</button>
<button type="button" class="btn btn-warning cancel">
<i class="glyphicon glyphicon-ban-circle"></i>
<span>Cancel upload</span>
</button>
</div>
<div class="col-lg-5">
<!-- The global file processing state -->
<span class="fileupload-process">
<div id="total-progress" class="progress progress-striped active" style="display:none" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
<div class="progress-bar progress-bar-success" style="width:0%;" data-dz-uploadprogress></div>
</div>
</span>
</div>
</div>
<div class="form-group">
<!-- HTML heavily inspired by http://blueimp.github.io/jQuery-File-Upload/ -->
<div class="table table-striped" class="files" id="previewsCover">
<div id="templateCover" class="file-row">
<!-- This is used as the file preview template -->
<div>
<span class="preview"><img data-dz-thumbnail /></span>
</div>
<div>
<p class="name" data-dz-name></p>
<strong class="error text-danger" data-dz-errormessage></strong>
</div>
<div>
<p class="size" data-dz-size></p>
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
<div class="progress-bar progress-bar-success" style="width:0%;" data-dz-uploadprogress></div>
</div>
</div>
<div>
<button type="button" class="btn btn-primary start">
<i class="glyphicon glyphicon-upload"></i>
<span>Start</span>
</button>
<button type="button" data-dz-remove class="btn btn-warning cancel">
<i class="glyphicon glyphicon-ban-circle"></i>
<span>Cancel</span>
</button>
<button type="button" data-dz-remove class="btn btn-danger delete">
<i class="glyphicon glyphicon-trash"></i>
<span>Delete</span>
</button>
</div>
</div>
</div>
<br>
</div>
<!-- </form>-->
<% end %>
</div>
</div>
</div>
<div class="card-footer">
<button type="submit" class="btn btn-sm btn-primary"><i class="fa fa-dot-circle-o"></i> Submit</button>
</div>
</div>
</div>
<!--/col-->
</div>
<!--/.row-->
</div>
</div>
my js file :
$( document ).ready(function()
{
var previewNode1 = document.querySelector("#templateCover");
console.log(previewNode1);
console.log(previewNode1.id);
previewNode1.id = "";
var previewTemplate1 = previewNode1.parentNode.innerHTML;
previewNode1.parentNode.removeChild(previewNode1);
var myDropzoneCover = new Dropzone("#dzCover", { // Make the whole body a dropzone
url: "/unitplans/create", // Set the url
thumbnailWidth: 80,
thumbnailHeight: 80,
parallelUploads: 20,
paramName: "unitplanphoto",
previewTemplate: previewTemplate1,
autoQueue: false, // Make sure the files aren't queued until manually added
previewsContainer: "#previewsCover", // Define the container to display the previews
clickable: ".fileinput-button2", // Define the element that should be used as click trigger to select files.
maxFilesize: 5,
acceptedFiles: ".png, .jpg, .jpeg", //is this correct? I got an error if im using this
init: function() {
this.on("success", function(file, response)
{
console.log(response);
file.serverId = response;
//alert(response);
});
this.on("removedfile", function(file)
{
//console.log(file);
//console.log(file.serverId);
if (!file.serverId)
{
return;
}
else
$.post("/unitplans/destroy?id=" + file.serverId);
});
this.options.previewaDropzone = false;
}
});
myDropzoneCover.on("addedfile", function(file) {
// Hookup the start button
file.previewElement.querySelector("#previewsCover .start").onclick = function() { myDropzoneCover.enqueueFile(file); };
//console.log(file);
});
// Update the total progress bar
myDropzoneCover.on("totaluploadprogress", function(progress) {
document.querySelector("#actionsCover #total-progress .progress-bar").style.width = progress + "%";
});
myDropzoneCover.on("sending", function(file) {
// Show the total progress bar when upload starts
document.querySelector("#actionsCover #total-progress").style.opacity = "1";
// And disable the start button
file.previewElement.querySelector("#previewsCover .start").setAttribute("disabled", "disabled");
//alert("sending");
});
// Hide the total progress bar when nothing's uploading anymore
myDropzoneCover.on("queuecomplete", function(progress) {
document.querySelector("#actionsCover #total-progress").style.opacity = "0";
//alert("complete");
});
// Setup the buttons for all transfers
// The "add files" button doesn't need to be setup because the config
// `clickable` has already been specified.
document.querySelector("#actionsCover .start").onclick = function() {
myDropzoneCover.enqueueFiles(myDropzoneCover.getFilesWithStatus(Dropzone.ADDED));
};
document.querySelector("#actionsCover .cancel").onclick = function() {
myDropzoneCover.removeAllFiles(true);
};
} );
controller file:
class UnitplansController < ApplicationController
def create
#unitplan = Unitplan.new(unitplan_params)
#respond_to do |format|
if #unitplan.save
render json: {message: "sukses", unitplanID: #unitplan.id}, status: 200
else
render json: { error: #unitplan.errors.full_messages.join(", ") }, status: 400
end
end
private
def unitplan_params
params.require(:unitplan).permit(:unitplanphoto)
end
end
somehow i can not make it to work,if i check dropzone request when i click submit, it always throw this error :
ActionController::ParameterMissing in UnitplansController#create
param is missing or the value is empty: unitplan
Your params appear to be missing the unitplan key that your unitplan_params method is looking for.
Try changing your paramNamevalue in your js file to this:
paramName: "unitplan[unitplanphoto]",
unitplan_params is acting as a whitelist for params to ensure you only pass approved params to your controller method, so you need to make sure your incoming params match the require and permit rules.
Related
I am using devise to handle registration with username/email and facebook. Everything is working except error messages. If I try to login from the modal and enter the wrong email or password, it doesn't do anything, but I can't figoure out how to get the error messages to appear in the modal form.
If I close the modal after an error and reopen it there are no errors and I'm not sure how to refresh the modal. If it is successfulit logs me in and takes me to my profile page, but if it is not succesful it just sits there. I'm not sure how to open it without clicking a link.
If I submit the registragion form with no or missing info it will go back to the regular sign up page and display the errors but I can't figure out how to hvae it reload the modal and display them there.
Here is the _login.html.erb model:
<div class="modal fade" id="login" tabindex="-1" aria-labelledby="login" aria-hidden="true">
<div class="modal-dialog modal-lg border-0">
<div class="modal-content border-0">
<div class="modal-content-head">
<h5 class="modal-title" id="login">Member Login</h5>
<button type="button" class="close text-right" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-12 col-md-4">
<div class="row border-0">
<div class="col-12 modal-content-subhead">
Login
</div>
</div>
<div class="row">
<div class="col modal-content">
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name), :remote => true) do |f| %>
<%= render "shared/error_messages", resource: resource %>
<div class="form-group row">
<div class="col-md-2 col-sm-12 col-form-label p-2">
<%= image_tag("layout/login/icon_reg_email.gif") %>
</div>
<div class="col-md-10 col-sm-12">
<%= f.email_field :email, class: "form-control shadow rounded", placeholder: "Email", :autofocus => true %>
</div>
</div>
<div class="form-group row">
<div class="col-md-2 col-sm-12 col-form-label p-2">
<%= image_tag("layout/login/icon_reg_locked.gif") %>
</div>
<div class="col-md-10 col-sm-12">
<%= f.password_field :password, class: "form-control shadow rounded", placeholder: "Password" %>
</div>
</div>
<% if devise_mapping.rememberable? -%>
<div>
<%= f.check_box :remember_me %> <%= f.label :remember_me, class: "form_small_text" %>
</div>
<% end -%>
<div class="form-group row text-center">
<div class="col-12">
<%= f.submit "Sign in", :class => 'btn reg-submit-btn' %>
</div>
</div>
<div class="modal-footer">
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to t(".forgot_your_password"), new_password_path(resource_name), class: "form_small_text" %><br />
<% end -%>
</div>
<% end %>
</div>
</div>
</div>
<div class="col-sm-12 col-md-1 text-center p-0">
<%= image_tag("layout/login/login_divider.gif") %>
</div>
<div class="col-sm-12 col-md-7">
<div class="row border-0">
<div class="col-12 modal-content-subhead">
Sign-Up
</div>
</div>
<div class="row">
<div class="col modal-content">
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), id: "form", :remote => true) do |f| %>
<%= render "shared/error_messages", resource: resource %>
<div class="form-group row">
<div class="col-md-2 col-sm-12 col-form-label p-2">
<%= image_tag("layout/login/icon_reg_name_37_33.gif") %>
</div>
<div class="col-md-5 col-sm-12">
<%= f.text_field :first_name, class: "form-control shadow rounded", placeholder: "First Name" %>
</div>
<div class="col-md-5 col-sm-12">
<%= f.text_field :last_name, class: "form-control shadow rounded", placeholder: "Last Name" %>
</div>
</div>
<div class="form-group row">
<div class="col-md-2 col-sm-12 col-form-label p-2">
<%= image_tag("layout/login/icon_reg_email.gif") %>
</div>
<div class="col-md-10 col-sm-12">
<%= f.email_field :email, class: "form-control shadow rounded", placeholder: "Email", :autofocus => true %>
</div>
</div>
<div class="form-group row">
<div class="col-md-2 col-sm-12 col-form-label p-2">
<div class="reg_tooltip" data-tooltip="
The club username will be used to easily share your club page on this website.
For example if your club username is my_club the url for your club page on this
site will be www.themathouse.com/clubs/my_club.
">
<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-question-diamond" fill="white" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M6.95.435c.58-.58 1.52-.58 2.1 0l6.515 6.516c.58.58.58 1.519 0 2.098L9.05 15.565c-.58.58-1.519.58-2.098 0L.435 9.05a1.482 1.482 0 0 1 0-2.098L6.95.435zm1.4.7a.495.495 0 0 0-.7 0L1.134 7.65a.495.495 0 0 0 0 .7l6.516 6.516a.495.495 0 0 0 .7 0l6.516-6.516a.495.495 0 0 0 0-.7L8.35 1.134z"/>
<path d="M5.255 5.786a.237.237 0 0 0 .241.247h.825c.138 0 .248-.113.266-.25.09-.656.54-1.134 1.342-1.134.686 0 1.314.343 1.314 1.168 0 .635-.374.927-.965 1.371-.673.489-1.206 1.06-1.168 1.987l.003.217a.25.25 0 0 0 .25.246h.811a.25.25 0 0 0 .25-.25v-.105c0-.718.273-.927 1.01-1.486.609-.463 1.244-.977 1.244-2.056 0-1.511-1.276-2.241-2.673-2.241-1.267 0-2.655.59-2.75 2.286zm1.557 5.763c0 .533.425.927 1.01.927.609 0 1.028-.394 1.028-.927 0-.552-.42-.94-1.029-.94-.584 0-1.009.388-1.009.94z"/>
</svg>
</div>
<%= image_tag("layout/login/icon_reg_name_37_33.gif") %>
</div>
<div class="form-check col-md-10 col-sm-12">
<%= f.text_field :username, class: "form-control shadow rounded", placeholder: "Username", id: "username" %>
</div>
</div>
<div class="form-group row">
<div class="col-md-2 col-sm-12 col-form-label p-2">
<%= image_tag("layout/login/icon_reg_locked.gif") %>
</div>
<div class="col-md-10 col-sm-12">
<%= f.password_field :password, class: "form-control shadow rounded", placeholder: "Password" %>
</div>
</div>
<div class="form-group row">
<div class="col-md-2 col-sm-12 col-form-label p-2">
<%= image_tag("layout/login/icon_reg_locked.gif") %>
</div>
<div class="col-md-10 col-sm-12">
<%= f.password_field :password_confirmation, class: "form-control shadow rounded", placeholder: "Confirm Password" %>
</div>
</div>
<div class="form-group row text-center">
<div class="col-12">
<%= f.submit "Sign up", :class => 'btn reg-submit-btn' %></div></p>
</div>
</div>
<% end %>
</div>
</div>
</div>
<div class="row">
<div class="col-11 text-center">
<%=link_to( image_tag("layout/facebook_login_200_42.gif"), user_facebook_omniauth_authorize_path) %>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
This is the applicatin_helpers.rb file:
module ApplicationHelper
def resource_name
:user
end
def resource
#resource ||= User.new
end
def devise_mapping
#devise_mapping ||= Devise.mappings[:user]
end
end
Both forms in the modal work. I can sign up with email/password or facebok and I can create an account and log in but I can't get the errors to show up in the modal.
I'm new to rails and I am trying to set modal for user login/registration. I am able to get the modal to work but I canot figure out how to get the devise registraion to work in the modal. I even tried createing a separate users/_new.html.erb file with my own registration form but when I try to submit from the modal I get an error no route matches post/. I tried change the devise/registration/new.html.erb form to _new.html.erb but when I try to load the page I get an error:
ActionView::Template::Error (undefined local variable or method `resource' for
#<#Class:0x000000000ebf9b50:0x000000000ec0de70>
Did you mean? rescue):
The above error happens when I render the standard devise/registrations/new.html.erb form. I converted it to a partial and move it to the shared folder.
<h1><%= t('.sign_up') %></h1>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, autofocus: true, autocomplete: 'email', class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :password %>
<%= f.password_field :password, autocomplete: 'current-password', class: 'form-control' %>
<% if #minimum_password_length %>
<small class="form-text text-muted"><%= t('devise.shared.minimum_password_length', count: #minimum_password_length) %></small>
<% end %>
</div>
<div class="form-group">
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation, autocomplete: 'current-password', class: 'form-control' %>
</div>
<div class="form-group">
<%= f.submit t('.sign_up'), class: 'btn btn-primary' %>
</div>
<% end %>
<%= render 'devise/shared/links' %>
The other way I tried it was posted the entire form in the modal on the nav page, but when I click submit, it goes to localhost.3000 and I get an error that no routes match post "/".
That form is, sorry, it's long, I have two forms in the modal:
<!-- Modal -->
<div class="modal fade" id="login" tabindex="-1" aria-labelledby="login" aria-hidden="true">
<div class="modal-dialog modal-lg border-0">
<div class="modal-content border-0">
<div class="modal-content-head">
<h5 class="modal-title" id="login">Member Login</h5>
<button type="button" class="close text-right" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-12 col-md-5">
<div class="row border-0">
<div class="col-12 modal-content-subhead">
Login
</div>
</div>
<div class="row">
<div class="col-12 modal-content">
<%= form_with(model: #user, class: "shadow p-3 mb-3 rounded text-light", local: true) do |f| %>
<div class="form-group row">
<div class="col-md-1 col-sm-12 col-form-label p-2">
<%= image_tag("layout/login/icon_reg_email.gif") %>
</div>
<div class="col-md-11 col-sm-12">
<%= f.email_field :email, class: "form-control shadow rounded", placeholder: "Email" %>
</div>
</div>
<div class="form-group row">
<div class="col-md-1 col-sm-12 col-form-label p-2">
<%= image_tag("layout/login/icon_reg_locked.gif") %>
</div>
<div class="col-md-11 col-sm-12">
<%= f.password_field :password, class: "form-control shadow rounded", placeholder: "Enter your password" %>
</div>
</div>
<div class="form-group row justify-content-center">
<div class="col-12">
<%= f.submit "Log in", class: "btn btn-outline-light btn-lg" %>
</div>
</div>
<% end %>
</div>
</div>
</div>
<div class="col-1 text-center">
<%= image_tag("layout/login/login_divider.gif") %>
</div>
<div class="col-sm-12 col-md-5">
<div class="row border-0">
<div class="col-12 modal-content-subhead">
Join
</div>
</div>
<div class="row">
<div class="col-12 modal-content">
<%= form_with(model: #user, class: "shadow p-3 mb-3 rounded text-light", local: true) do |f| %>
<div class="form-group row">
<div class="col-md-1 col-sm-12 col-form-label p-2">
<%= image_tag("layout/login/icon_reg_name_37_33.gif") %>
</div>
<div class="col-md-11 col-sm-12">
<%= f.text_field :first_name, class: "form-control shadow rounded", placeholder: "First Name" %>
</div>
</div>
<div class="form-group row">
<div class="col-md-1 col-sm-12 col-form-label p-2">
<%= image_tag("layout/login/icon_reg_name_37_33.gif") %>
</div>
<div class="col-md-11 col-sm-12">
<%= f.text_field :last_name, class: "form-control shadow rounded", placeholder: "Last Name" %>
</div>
</div>
<div class="form-group row">
<div class="col-md-1 col-sm-12 col-form-label p-2">
<%= image_tag("layout/login/icon_reg_email.gif") %>
</div>
<div class="col-md-11 col-sm-12">
<%= f.email_field :email, class: "form-control shadow rounded", placeholder: "Email" %>
</div>
</div>
<div class="form-group row">
<div class="col-md-1 col-sm-12 col-form-label p-2">
<%= image_tag("layout/login/icon_reg_locked.gif") %>
</div>
<div class="col-md-11 col-sm-12">
<%= f.password_field :password, class: "form-control shadow rounded", placeholder: "Enter your password" %>
</div>
</div>
<div class="form-group row justify-content-center">
<div class="col-12">
<%= f.submit "Log in", class: "btn btn-outline-light btn-lg" %>
</div>
</div>
<% end %>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-11 text-center">
<%=link_to( image_tag("layout/facebook_login_200_42.gif"), user_facebook_omniauth_authorize_path) %>
</div>
</div>
</div>
</div>
</div>
</div>
---
Here is my routes.rb
~~~code
Rails.application.routes.draw do
devise_for :users, controllers: {omniauth_callbacks: 'omniauth'}
root 'pages#index'
get 'about', to: 'pages#about'
resources :users, param: :username
resources :clubs, param: :club_username
end
I'm happy to create my own or use the devise with some modifications but I just can't figure out how to do either.
Any help would be gretly appreciated.
Thanks,
Scott
I did some more searching and was able to get it to work. I uninstalled devise and tried it but couldn't get it to work so I reinstalled devise and omniauth and find an explanation to incorporating the devise forms into my app.
I installed the devise bootstrap views then in the layouts folder I created a partial named _login_html.erb and copied the login form and the sign upforms side-by-side:
<div class="modal fade" id="login" tabindex="-1" aria-labelledby="login" aria-hidden="true">
<div class="modal-dialog modal-lg border-0">
<div class="modal-content border-0">
<div class="modal-content-head">
<h5 class="modal-title" id="login">Member Login</h5>
<button type="button" class="close text-right" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-12 col-md-4">
<div class="row border-0">
<div class="col-12 modal-content-subhead">
Login
</div>
</div>
<div class="row">
<div class="col modal-content">
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name), :remote => true) do |f| %>
<div class="form-group row">
<div class="col-md-2 col-sm-12 col-form-label p-2">
<%= image_tag("layout/login/icon_reg_email.gif") %>
</div>
<div class="col-md-10 col-sm-12">
<%= f.email_field :email, class: "form-control shadow rounded", placeholder: "Email", :autofocus => true, class: "form-control shadow rounded", placeholder: "Email" %>
</div>
</div>
<div class="form-group row">
<div class="col-md-2 col-sm-12 col-form-label p-2">
<%= image_tag("layout/login/icon_reg_locked.gif") %>
</div>
<div class="col-md-10 col-sm-12">
<%= f.password_field :password, class: "form-control shadow rounded", placeholder: "Password" %>
</div>
</div>
<% if devise_mapping.rememberable? -%>
<div>
<%= f.check_box :remember_me %> <%= f.label :remember_me, class: "form_small_text" %>
</div>
<% end -%>
<div class="form-group row text-center">
<div class="col-12">
<%= f.submit "Sign in", :class => 'btn reg-submit-btn' %>
</div>
</div>
<div class="modal-footer">
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to t(".forgot_your_password"), new_password_path(resource_name), class: "form_small_text" %><br />
<% end -%>
</div>
<% end %>
</div>
</div>
</div>
<div class="col-sm-12 col-md-1 text-center p-0">
<%= image_tag("layout/login/login_divider.gif") %>
</div>
<div class="col-sm-12 col-md-7">
<div class="row border-0">
<div class="col-12 modal-content-subhead">
Sign-Up
</div>
</div>
<div class="row">
<div class="col modal-content">
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), id: "form", :remote => true) do |f| %>
<%= devise_error_messages! %>
<div class="form-group row">
<div class="col-md-2 col-sm-12 col-form-label p-2">
<%= image_tag("layout/login/icon_reg_name_37_33.gif") %>
</div>
<div class="col-md-5 col-sm-12">
<%= f.text_field :first_name, class: "form-control shadow rounded", placeholder: "First Name" %>
</div>
<div class="col-md-5 col-sm-12">
<%= f.text_field :last_name, class: "form-control shadow rounded", placeholder: "Last Name" %>
</div>
</div>
<div class="form-group row">
<div class="col-md-2 col-sm-12 col-form-label p-2">
<%= image_tag("layout/login/icon_reg_email.gif") %>
</div>
<div class="col-md-10 col-sm-12">
<%= f.email_field :email, class: "form-control shadow rounded", placeholder: "Email", :autofocus => true %>
</div>
</div>
<div class="form-group row">
<div class="col-md-2 col-sm-12 col-form-label p-2">
<div class="reg_tooltip" data-tooltip="
The club username will be used to easily share your club page on this website.
For example if your club username is my_club the url for your club page on this
site will be www.themathouse.com/clubs/my_club.
">
<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-question-diamond" fill="white" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M6.95.435c.58-.58 1.52-.58 2.1 0l6.515 6.516c.58.58.58 1.519 0 2.098L9.05 15.565c-.58.58-1.519.58-2.098 0L.435 9.05a1.482 1.482 0 0 1 0-2.098L6.95.435zm1.4.7a.495.495 0 0 0-.7 0L1.134 7.65a.495.495 0 0 0 0 .7l6.516 6.516a.495.495 0 0 0 .7 0l6.516-6.516a.495.495 0 0 0 0-.7L8.35 1.134z"/>
<path d="M5.255 5.786a.237.237 0 0 0 .241.247h.825c.138 0 .248-.113.266-.25.09-.656.54-1.134 1.342-1.134.686 0 1.314.343 1.314 1.168 0 .635-.374.927-.965 1.371-.673.489-1.206 1.06-1.168 1.987l.003.217a.25.25 0 0 0 .25.246h.811a.25.25 0 0 0 .25-.25v-.105c0-.718.273-.927 1.01-1.486.609-.463 1.244-.977 1.244-2.056 0-1.511-1.276-2.241-2.673-2.241-1.267 0-2.655.59-2.75 2.286zm1.557 5.763c0 .533.425.927 1.01.927.609 0 1.028-.394 1.028-.927 0-.552-.42-.94-1.029-.94-.584 0-1.009.388-1.009.94z"/>
</svg>
</div>
<%= image_tag("layout/login/icon_reg_name_37_33.gif") %>
</div>
<div class="form-check col-md-10 col-sm-12">
<%= f.text_field :username, class: "form-control shadow rounded", placeholder: "Username", id: "username" %>
</div>
</div>
<div class="form-group row">
<div class="col-md-2 col-sm-12 col-form-label p-2">
<%= image_tag("layout/login/icon_reg_locked.gif") %>
</div>
<div class="col-md-10 col-sm-12">
<%= f.password_field :password, class: "form-control shadow rounded", placeholder: "Password" %>
</div>
</div>
<div class="form-group row">
<div class="col-md-2 col-sm-12 col-form-label p-2">
<%= image_tag("layout/login/icon_reg_locked.gif") %>
</div>
<div class="col-md-10 col-sm-12">
<%= f.password_field :password_confirmation, class: "form-control shadow rounded", placeholder: "Confirm Password" %>
</div>
</div>
<div class="form-group row text-center">
<div class="col-12">
<%= f.submit "Sign up", :class => 'btn reg-submit-btn' %></div></p>
</div>
</div>
<% end %>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
To make it work I added the following code to the helpers_application.
def resource_name
:user
end
def resource
#resource ||= User.new
end
def devise_mapping
#devise_mapping ||= Devise.mappings[:user]
end
I think that's it.
What would be the cause of me only being able to select the first radio button, but not the second. Here is what my form looks like.
`
<%= form_for [#item, Calendar.new] do |f| %>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<%= f.text_field :start_date, readonly: true, value: Date.today, class: "form-control datepicker" %>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<%= f.text_field :end_date, readonly: true, value: Date.today, class: "form-control datepicker" %>
</div>
</div>
</div>
<div class="form-group">
<div class="btn-group" data-toggle="buttons-radio">
<%= f.collection_radio_buttons :status, Calendar.statuses, :first, :first, checked: Calendar.statuses.first do |b|
b.radio_button + b.label {b.text.split("_").join("").capitalize}
end %>
</div>
</div>
<div class="row new-pricing">
<div class="col-md-10">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">$</span>
<%= f.text_field :item_price, class: "form-control", value: #item.item_price, required: true %>
</div>
</div>
</div>
<div class="col-md-2">
<p style="margin-top: 10px"> Per Day </p>
</div>
</div>
<div class="no-pricing hide">
</div>
<div class="form-group">
<%= f.button "Save", type: :submit, class: "btn btn-success" %>
</div>
<% end %>`
Here is what the html looks like when I click on the "Not available" button. The checked always remains on the first value input button.
The html in the inspection window.
How can I go about fixing this. Sorry if this was an easy question.
Webpage
-> Sections (Has Many)
-> Header (Has One)
-> HeaderTabs (Has Many)
I make nested form for above structure and it's display me properly,
But When I'm adding new header_tabs on click of 'Add new Header Tab', It's add new fields but the indexing value is same as first one.
<div class="header_tabs_forms">
<div class="form-group">
<label class="control-label col-lg-3"> </label>
<div class="col-lg-1">
<input type="hidden" value="false" name="webpage[section_headers_attributes][0][header_attributes][header_tabs_attributes][0][_destroy]" id="webpage_section_headers_attributes_0_header_attributes_header_tabs_attributes_0__destroy"><a class="btn btn-danger btn-xs rmhdrtab remove_nested_fields" data-association="header_tabs" href="javascript:void(0)"><i class="fa fa-close"></i></a>
</div>
<div class="col-lg-6 header_tabs">
<input placeholder="Write Tab Name" class="form-control form-ctr100 required" require="true" style="width:100%;" type="text" name="webpage[section_headers_attributes][0][header_attributes][header_tabs_attributes][0][tab_name]" id="webpage_section_headers_attributes_0_header_attributes_header_tabs_attributes_0_tab_name">
<div class="error"></div>
</div>
<div class="col-lg-2 header_tabs">
<input class="form-control form-ctr2 required" min="1" require="true" type="text" value="1" name="webpage[section_headers_attributes][0][header_attributes][header_tabs_attributes][0][position]" id="webpage_section_headers_attributes_0_header_attributes_header_tabs_attributes_0_position">
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-3"> </label>
<div class="col-lg-1">
<input type="hidden" value="false" name="webpage[section_headers_attributes][0][header_attributes][header_tabs_attributes][0][_destroy]" id="webpage_section_headers_attributes_0_header_attributes_header_tabs_attributes_0_header_tabs__destroy"><a class="btn btn-danger btn-xs rmhdrtab remove_nested_fields" data-association="header_tabs" href="javascript:void(0)"><i class="fa fa-close"></i></a>
</div>
<div class="col-lg-6 header_tabs">
<input placeholder="Write Tab Name" class="form-control form-ctr100 required" require="true" style="width:100%;" type="text" name="webpage[section_headers_attributes][0][header_attributes][header_tabs_attributes][0][tab_name]" id="webpage_section_headers_attributes_0_header_attributes_header_tabs_attributes_0_header_tabs_tab_name">
<div class="error"></div>
</div>
<div class="col-lg-2 header_tabs">
<input class="form-control form-ctr2 required" min="1" require="true" type="text" value="1" name="webpage[section_headers_attributes][0][header_attributes][header_tabs_attributes][0][position]" id="webpage_section_headers_attributes_0_header_attributes_header_tabs_attributes_0_header_tabs_position">
</div>
</div>
</div>
check - webpage[section_headers_attributes][0][header_attributes][header_tabs_attributes][0]
the index value [header_tabs_attributes][0] are same for tabs.
Can you please why is it same ? and what is the solutions ?
Update 2 - Code for the form.
<%= nested_form_for webpage, html: {class: 'form-horizontal header-validation-webpage'}, remote: true do |form_webpage| %>
<%= hidden_field_tag :type, params[:type] %>
<%= form_webpage.fields_for :sections do |form_section| %>
<div class="form-group">
<%= form_section.label :name, class: 'control-label col-lg-3' %>
<div class="col-lg-8">
<%= form_section.text_field :name, placeholder: 'Write your section name!', class: 'form-control' %>
</div>
</div>
<div class="form-group">
<%= form_section.label :position, class: 'control-label col-lg-3' %>
<div class="col-lg-8">
<%= form_section.number_field :position, placeholder: 'Position', class: 'form-control', min: 1 %>
</div>
</div>
<%= form_section.fields_for :header do |form_header| %>
<legend><small>Tab Name & Position Detail</small></legend>
<div class="header_tabs_forms">
<%= form_header.fields_for :header_tabs, :wrapper => false do |form_htab| %>
<%# index = Time.now().strftime("%d%m%Y%I%M%S%3N") %>
<div class="form-group">
<label class="control-label col-lg-3"> </label>
<div class="col-lg-1">
<%= form_htab.link_to_remove "<i class='fa fa-close'></i>".html_safe, class: 'btn btn-danger btn-xs rmhdrtab' %>
</div>
<div class="col-lg-6 header_tabs">
<%= form_htab.text_field :tab_name, placeholder: 'Write Tab Name', class: 'form-control form-ctr100 required', require: true, style: 'width:100%;' %>
<div class='error'><%= display_error_messages webpage.errors, [:'header.header_tabs.tab_name'] %></div>
</div>
<div class="col-lg-2 header_tabs">
<%= form_htab.text_field :position, class: 'form-control form-ctr2 required', min: 1, require: true %>
</div>
</div>
<% end %>
</div>
<p class="text-right">
<%= form_header.link_to_add "<i class='fa fa-plus'></i> Add New Tab".html_safe, :header_tabs, data: {target: '.header_tabs_forms'} %>
</p>
<% end %>
<% end %>
<hr>
<div class="form-group">
<div class="col-lg-offset-3 col-lg-9">
<%= form_webpage.submit 'Save', class: 'btn btn-primary', data: {disable_with: 'Loading...'} %>
</div>
</div>
<% end %>
Is it possible to add params to url while rendering view on controller?
Here I'm trying to add tab=2 on the url.So that my new url looks like localhost:3000/organizations/new?tab=2
I tried the following code
render 'organizations/new', tab: 2
but it neither change the URL nor add the params on URL it just render the view.
I also tried render 'organizations/new?tab=2' It throws ActionView::MissingTemplate.
EDIT 1
Here is my organization/new.html.erb code
<!-- START PAGE CONTAINER -->
<div class="page-container page-navigation-top-fixed" id="organization-new">
<!-- PAGE CONTENT -->
<%= render 'shared/navigation' %>
<div class="page-content">
<%= render 'shared/header' %>
<!-- PAGE CONTENT WRAPPER -->
<div class="page-content-wrap">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default tab-panel">
<div class="panel-body">
<div class="tab-container" id="tabs">
<ul class="nav nav-tabs" role="tablist">
<li class="active">
<a href="#tab-1" data-toggle="tab">
<%= t('admins.create_organization') %>
</a>
</li>
<li class="disabled">
<a href="#tab-2" data-toggle="tab" class="disabled">
<%= t('organization.add_profile') %>
</a>
</li>
</ul>
<div class="org tab-content">
<div class="tab-pane fade in active" id="tab-1">
<h3></h3>
<%= render 'organizations/add_edit_org_form' %>
</div>
<div class="tab-pane fade" id="tab-2">
<h3></h3>
<%= render 'organizations/add_business_profile_tab' %>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- END PAGE CONTENT WRAPPER -->
<%= render 'shared/footer' %>
</div>
<!-- END PAGE CONTENT -->
</div>
<!-- END PAGE CONTAINER -->
here is my 'organizations/add_edit_org_form' partial which is renders on first tab
<%= form_for (#organization), html: {class: 'form-horizontal organization-form', id: 'add_edit_organization'} do |f| %>
<div class="form-group">
<%= f.label(:name, t('organization.label_name'), class: 'col-md-3 col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.text_field(:name, class: 'form-control', organization_id: #organization.id) %>
<span class="org-error-block text-danger text-danger" id="organization_name_error"></span>
</div>
</div>
<div class="form-group">
<%= f.label(:abbreviation, t('organization.label_abbr'), class: 'col-md-3 col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.text_field(:abbreviation, class: 'form-control', organization_id: #organization.id) %>
<span class="org-error-block text-danger text-danger" id="organization_abbreviation_error"></span>
</div>
</div>
<div class="form-group">
<%= f.label(:organization_type, t('organization.label_type'), class: 'col-md-3
col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.select(:organization_type, options_for_organization_type, {}, class: 'form-control select') %>
<span class="org-error-block text-danger text-danger" id="organization_type_error"></span>
</div>
</div>
<div class="form-group">
<%= f.label(:primary_currency, t('organization.label_primary_currency'), class: 'col-md-3 col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.select(:primary_currency, options_for_primary_currency, {}, class: 'form-control select') %>
<span class="org-error-block text-danger text-danger" id="organization_primary_currency_error"></span>
</div>
</div>
<div class="form-group">
<%= f.label(:status, t('organization.label_status'), class: 'col-md-3 col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.select(:status, options_for_status, {}, class: 'form-control select') %>
<span class="org-error-block text-danger text-danger" id="organization_status_error"></span>
</div>
</div>
<div class="form-group">
<%= f.label(:country_id, t('organization.label_country'), class: 'col-md-3 col-xs-12
control-label') %>
<div class="col-md-4 col-xs-12 select-country-options">
<%= f.select(:country_id, options_for_countries, {}, class: 'form-control select') %>
<span class="org-error-block text-danger text-danger" id="organization_country_id_error"></span>
</div>
</div>
<div class="form-group">
<%= f.label(:payment_method_id, t('organization.label_payment_method'), class: 'col-md-3 col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.select(:payment_method_id, options_for_payment_methods, {}, class: 'form-control select') %>
</div>
</div>
<div class="panel-footer">
<button class="btn btn-primary ajax-spinner pull-right">
<%= t('organization.label_submit') %>
<span class="fa fa-floppy-o fa-right"></span>
</button>
<i class="fa fa-spinner fa-pulse fa-2x pull-right"></i>
</div>
<% end %>
and here is my another partials 'organizations/add_business_profile_tab' which is renders on second tab
<%= form_for (#business_profile), html: {class: 'form-horizontal', id: 'add_business_profile', multipart: true} do |f| %>
<div class="form-group">
<label class="col-md-3 col-xs-12 control-label"><%= t('business_profile.upload_your_logo') %></label>
<div class="col-md-4 col-xs-12 ">
<div class="image-frame" id="upload_logo_div">
<%= image_tag 'upload.jpg', class: 'image-frame', id: 'logo_image' %>
</div>
<%= f.file_field(:logo, id: 'logo_upload_btn') %>
<span class="org-error-block text-danger text-danger" id="logo_upload_btn_error"></span>
<div id="date_picker_container"></div>
</div>
</div>
<div class="form-group">
<%= f.hidden_field(:organization_id, value: #organization.id, id: 'organization_id') %>
<%= f.label(:email, t('business_profile.email'), class: 'col-md-3 col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.text_field(:email, class: 'form-control', organization_id: #organization_id) %>
<span class="org-error-block text-danger text-danger" id="business_profile_email_error"></span>
</div>
</div>
<div class="form-group">
<%= f.label(:address, t('business_profile.address'), class: 'col-md-3
col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.text_field(:address, class: 'form-control') %>
<span class="org-error-block text-danger text-danger" id="business_profile_address_error"></span>
</div>
</div>
<div class="form-group">
<%= f.label(:phone, t('business_profile.phone'), class: 'col-md-3 col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.text_field(:phone, class: 'form-control') %>
<span class="org-error-block text-danger text-danger" id="business_profile_phone_error"></span>
</div>
</div>
<div class="form-group">
<%= f.label(:contact_person_name, t('business_profile.contact_person_name'), class: 'col-md-3 col-xs-12 control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.text_field(:contact_person_name, class: 'form-control') %>
<span class="org-error-block text-danger text-danger" id="business_profile_contact_person_name_error"></span>
</div>
</div>
<div class="form-group ">
<%= f.label(:registration_date, t('business_profile.registration_date'), class: 'col-md-3 col-xs-12
control-label') %>
<div class="col-md-4 col-xs-12">
<%= f.text_field(:registration_date, class: 'form-control', autocomplete: 'off', value: #business_profile.registration_date.nil? ? '' : #business_profile.registration_date.strftime('%m/%d/%Y')) %>
<span class="org-error-block text-danger text-danger" id="business_profile_registration_date_error"></span>
</div>
</div>
<div class="form-group">
<div class="col-md-4 col-xs-12">
<%= f.hidden_field(:organization_id) %>
<input type="hidden" value=<%= Date.today.strftime('%Y-%m-%d') %> name="today_date" id="today_date">
<span class="org-error-block text-danger text-danger" id="business_profile_organization_id_error"></span>
</div>
</div>
<div class="panel-footer">
<button class="btn btn-primary pull-right">
<%= t('business_profile.label_submit') %>
<span class="fa fa-floppy-o fa-right"></span>
</button>
</div>
NOTE
I want to be stay on second tab after the form submission on both success and failure cases.
try this one.
render 'organizations/new', :locals => {tab:2}
Another solution:
On new organizations link pass the tab like
link_to 'New Organization', new_organization_path(tab: 2)
This will exactly same as you want
localhost:3000/organizations/new?tab=2
Normally when render method is executed in controller, it parses the targeted view template in your case organizations/new. It has nothing to do with changing the HTTP request URL and params.
instead you do like this
form_for (#organization, url: organization_path(#organization, tab: 2) )
This will make the params tab=2 in the address bar after the completion of the request.
Moreover, it looks like the term tab=2 is not fixed, it might change at run time so you may use jQuery to modify the action attribute of the form like
$('#target_form').attr('action', old_value + '?tab=2');