<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<%= link_to "My Ozone", root_path, class: "navbar-brand" %>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
<%= form_tag zipcode_path, :method => 'POST' do %>
<div class="form-inline my-2 my-lg-0">
<%= text_field_tag 'zipcode', nil, placeholder: "Search Zipcode", class: "form-control mr-sm-2" %>
<%= submit_tag 'Search', class: 'btn btn-outline-secondary my-2 my-sm-0' %>
</div>
<% end %>
</div>
</nav>
I've finished a Ruby on Rails project that displays ozone information based on the zip code searched for. However, I can't seem to get the field and submit button next to each other. I've tried a variety of different things like changing the div class and wrapping things in a form tag, but it doesn't seem to resolve the issue. Looking for help with getting the items aligned on the same row.
You need to use d-flex instead of form-inline class in Bootstrap 5.
Dropped form-specific layout classes for our grid system in Bootstrap 5. Use our grid
and utilities instead of .form-group, .form-row, or .form-inline - more details here
Your code should be as below:
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<%= link_to "My Ozone", root_path, class: "navbar-brand" %>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
<%= form_tag zipcode_path, :method => 'POST' do %>
<div class="d-flex my-2 my-lg-0">
<%= text_field_tag 'zipcode', nil, placeholder: "Search Zipcode", class: "form-control mr-sm-2" %>
<%= submit_tag 'Search', class: 'btn btn-outline-secondary my-2 my-sm-0' %>
</div>
<% end %>
</div>
</nav>
Related
I have a modal that's inside a Bootstrap Card for a confirmation if the user really wants to cancel a booking. The problem is that it doesn't show up when clicked. I see the fade effect and that's about it.
<% if Date.current.strftime('%Y-%m-%d') == data.formatted_date_time_for_comparison %>
<%= f.submit 'Cancel Booking', class: "btn btn-danger" %>
<% else %>
<button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#myModal">Cancel Booking</button>
<div class="modal fade text-dark" id="myModal">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">Confirm Cancellation</h3>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
Are you sure you want to cancel this booking?
</div>
<div class="modal-footer">
<%= f.submit 'Cancel Booking', class: "btn btn-danger" %>
<button type="button" class="btn btn-primary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<% end %>
It compares the current date to the date of the booking's departure date and it gives a submit button straight to the controller, which in turn rejects it because cancelling on the same date isn't allowed. If that's not the case it gives a button for a modal to activate.
I'm mostly sure it's because of it buried beneath divs, specifically divs with bootstrap card classes.
Here are its parent divs:
<div class="margin-top" style="width: 600px;">
<div class="bg-dark p-3 rounded">
<h3>Reservations</h3>
</div>
<div id="accordion" class="mt-3 mb-4">
<div class="card bg-dark">
<% #reservations.reverse().each do |data| %>
<a class="btn text-light card-header" data-bs-toggle="collapse" href="#id-<%= data.id %>">
<div class="row" style="text-align: left;">
<div class="col">
<strong>Name: </strong><%= data.name %><br><br>
<!-- other records -->
</div>
<div class="col">
<strong>Departure: </strong><%= data.departure %><br>
<!-- other records -->
</div>
</div>
</a>
<div id="id-<%= data.id %>" class="collapse" data-bs-parent="#accordion">
<div class="card-body">
<div class="row">
<div class="col">
<strong>Base Price: </strong><%= data.base_price %><br>
<!-- other records -->
</div>
<div class="col d-flex align-items-end justify-content-end">
<%= form_for #cancellation, url: del_rsrv_path do |f| %>
<%= f.hidden_field :id, value: data.id %>
<%= f.hidden_field :datetime, value: data.formatted_date_time_for_comparison %>
<!-- code posted above here -->
I checked and it does work just below the first div (didn't check on deeper divs), but the problem would be passing the form params there. I'm asking if there's a workaround in either situation.
EDIT: I renamed the data-bs-target name and its respective id name and it somehow works now.
I am working on a project using Rails.
I am trying to put an alert box inside a delete link.
For that, I tried using normal alert box and it was working fine, Then I used bootstrap modal, since i was using bootstrap modal code inside the loop, it was creating modal for each loop, so i had to remove it.
Now I used Data-Confirm Modal and I followed their documentation properly, but still I am not getting any proper results.
My question is, Is there any other way to use modal without using it inside a loop.
The code is given below, Kindly give me some suggestions
<div class="row">
<% #user.each do |c| %>
<div class="col-lg-3">
<div class="card bot-card card-1">
<div class="row">
<div class="col-lg-8">
<p class="d-flex align-items-center">
<span class="green-dot"></span>
<span class="online-text">online</span>
</p>
</div>
<div class="col-lg-1">
<%= link_to user_path(c.id), method: :delete, data: {confirm: 'Are
you sure?'} do %>
<i class="fa fa-trash" aria-hidden="true" ></i>
<%end%>
</div>
<div class="col-lg-1">
<i class="far fa-clone">
</i>
</div>
</div>
<img src="assets/avatar-2.png" alt="Avatar" class="avatar" >
<div class="card-body">
<p class="card-title"><%= c.name %></p>
<p class="card-text"><%= c.description %></p>
<div class="d-flex justify-content-end card-link">
View Details
Edit
</div>
</div>
</div>
</div>
</div>
<% end %>
<div class="col-lg-3">
<div class="card card-2 d-flex align-items-center justify-content-center">
<p>
Create user
</p>
<p>
Create From Template
</p>
</div>
</div>
</div>
Code using bootstrap modal
<div class="row">
<% #user.each do |c| %>
<div class="col-lg-3">
<div class="card card-1">
<div class="row">
<div class="col-lg-8">
<p class="d-flex align-items-center">
<span class="green-dot"></span>
<span class="online-text">online</span>
</p>
</div>
<div class="col-lg-1">
<i class="fa fa-trash" aria-hidden="true" data-toggle="modal" data-
target="#exampleModal"></i>
</div>
<div class="col-lg-1">
<i class="far fa-clone">
</i>
</div>
</div>
<img src="assets/avatar-2.png" alt="Avatar" class="avatar" >
<div class="card-body">
<p class="card-title"><%= c.name %></p>
<p class="card-text"><%= c.description %></p>
<div class="d-flex justify-content-end card-link">
View Details
Edit
</div>
</div>
</div>
</div>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-
labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Delete
Confirmation</h5>
<button type="button" class="close" data-dismiss="modal" aria-
label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Are you sure?
</div>
<div class="modal-footer">
<button class="btn btn-danger">
<%= link_to 'Ok', user_path(c.id), method: :delete %>
</button>
</div>
</div>
</div>
</div>
<% end %>
<div class="col-lg-3">
<div class="card card-2 d-flex align-items-center justify-content-center">
<p>
Create user
</p>
<p>
Create From Template
</p>
</div>
</div>
</div>
I am new to ruby on rails, I have been recommended to using a sidebar so that on most pages it will show what I want. I currently have an application on its own page called Todo List. It simply let you create a task and displays the tasks. It runs on its own page. Now I want to move that app and let it function in my sidebar. I have implemented my sidebar as follow.
/views/layouts/application (in body)
<%= yield :sidebar %>
/views/myapp1/index
<% content_for(:sidebar) do %>
<% render :partial => "layouts/sidebar" %>
<% end %>
/views/layouts/_sidebar
<% if logged_in? %>
<div id="mySidenav" class="sidenav">
<div class="row", id="container_todo_lists">
<%= render #todo_lists %>
</div>
<div class="links" data-toggle="modal" data-target="#mynewtodo_list">
<%= link_to('New Todo List', 'javascript:;', :id => :random) %>
</div>
×
</div>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ Todo List</span>
<script>
function openNav() {document.getElementById("mySidenav").style.width = "250px";}
function closeNav() {document.getElementById("mySidenav").style.width = "0";}
</script>
<% end %>
<!-- Modal create action -->
<%= form_for(#todo_list, remote: true) do |f| %>
<div class="modal fade" id="mynewtodo_list" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Todo</h4>
</div>
<div class="modal-body">
<div class="field">
<%= f.label :title %><br>
<%= f.text_area :title, class: "form-control todo_list_title" %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_area :description, class: "form-control todo_list_content" %>
</div>
</div>
<div class="modal-footer">
<%= submit_tag "Create", class: "btn btn-primary" %>
<button type="button" class="btn btn-default" data-dismiss="modal" id="mynewtodo_listclose">Close</button>
</div>
</div>
</div>
</div>
<% end %>
<!-- Modal -->
I get this error
'nil' is not an ActiveModel-compatible object. It must implement :to_partial_path.
I think I know part of the problem is my
#todo_lists
Because I tried to called the sidebar on my todo_list page and it works, but the sidebar messed up my original application so that when I press edit and show it would turn the screen grey. Any suggestion is greatly appreciated. Thanks in advance.
/views/todo_lists/_todo_list.html.erb
<div class="text-center" id="todo_list_<%= todo_list.id %>">
<h3 class="panel-title"><%= todo_list.title %>
<sup style="color: #3BB2D6; position: absolute; top: 5px; right: 15px; text-align:right;">
(<%= time_ago_in_words(todo_list.created_at) %>)
</sup>
</h3>
<p><%= todo_list.description %></p>
<div class="row" role="group">
<div class="links1" data-toggle="modal" data-target="#myupdatetodo_list_<%= todo_list.id %>">
<%= link_to('Edit', 'javascript:;', :id => :random) %>
</div>
<div class="links1" data-toggle="modal" data-target="#myitemtodo_list_<%= todo_list.id %>">
<%= link_to('Show', 'javascript:;', :id => :random) %>
</div>
<div class="links1">
<%= link_to 'Destroy', todo_list, method: :delete, remote: true %>
</div>
</div>
<!-- Modal - update posts -->
<%= form_for(todo_list, :method => :put, remote: true) do |f| %>
<div class="modal fade" id="myupdatetodo_list_<%= todo_list.id %>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Edit</h4>
</div>
<div class="modal-body">
<div class="field">
<%= f.label :title %><br>
<%= f.text_area :title, class: "form-control" %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_area :description, class: "form-control" %>
</div>
</div>
<div class="modal-footer">
<button type="button" id="myupdatebutton_<%= todo_list.id %>" class="btn btn-default" data-dismiss="modal">Close</button>
<%= submit_tag "Update", class: "btn btn-primary" %>
</div>
</div>
</div>
</div>
<% end %>
<!-- Modal -->
<!-- Modal - item posts -->
<%= form_for(todo_list, :method => :put, remote: true) do |f| %>
<div class="modal fade" id="myitemtodo_list_<%= todo_list.id %>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Items</h4>
</div>
<div class="modal-body">
<h3><%= todo_list.title %></h3>
<p><%= todo_list.description %></p>
</div>
<div class="modal-footer">
<button type="button" id="myitembutton_<%= todo_list.id %>" class="btn btn-default" data-dismiss="modal">Close</button>
<%= submit_tag "Add Item", class: "btn btn-primary" %>
</div>
</div>
</div>
</div>
<% end %>
<!-- Modal -->
In your case, that is because the #todo_lists isn't being set, I'm sure if you go back to the previous url that was rendering the view, the sidebar would show.
A way to resolve is to ensure it's set on every page as such:
class ApplicationController
before_action :set_to_do_lists
def set_to_do_lists
#todo_lists ||= TodoList.all #assign this to what's in your todo_lists_path
end
end
With that I guess your app should be fixed
Some reason this form worked locally, but now when I put the code on a Digital Ocean droplet the submit button no longer submits.. It doesn't do anything, and does not go to the controller. Not sure what's wrong. Code for partial is attached below:
<%= form_for(#amazon, url: amazon_index_path) do |f| %>
<div class="col-md-12 well"> <!-- This is the first well, and says take
up all the 8 rows we have-->
<div class="form-group">
<h4>Merchant Id</h4>
<div class="input-group input-group-lg">
<div class="input-group-addon border">
<span class="glyphicon glyphicon-user" aria-hidden="true"></span>
</div>
<%= f.text_field :merchant_id, :placeholder => "Merchant Id",
class: "form-control input-group-lg", required: true %>
</div>
</div>
<div class="form-group">
<h4>
Marketplace
</h4>
<div class="input-group input-group-lg">
<div class="input-group-addon border">
<span class="glyphicon glyphicon-globe" aria-hidden="true"></span>
</div>
<%= f.select :marketplace,
grouped_options_for_select(marketplace_listing),
{}, class: 'form-control input-group-lg' %>
</div>
</div>
<div class="form-group">
<h4>MWS Auth Token</h4>
<div class="input-group input-group-lg">
<div class="input-group-addon border">
<span class="glyphicon glyphicon-file" aria-hidden="true"></span>
</div>
<%= f.text_field :auth_token, hide_label: true,:placeholder => "MWS
Auth Token",
class: "form-control input-group-lg", required: true %>
</div>
</div>
<%= f.submit 'Save Profile', class: 'btn btn-green btn-lg btn-block' %>
</div> <!--this is the well and takes up the 8 columns -->
<% end %>
I did just get this error in the console:
enteReferenceError: ShopifyApp is not defined
ShopifyApp.ready(function(){r code here
I have posted this before but no one has reply me on my problem. However, after trying for few days. I encountered something funny.
My View Code
<% provide(:title, "Log in") %>
<div class="center jumbotron">
<h1> Kaching </h1>
<div class = "row" >
<div class="col-md-6 col-md-offset-3">
<%= form_for(:session, url: login_path) do |f| %>
<%= f.label :logID, "Log ID" %>
<%= f.text_field :logID %>
<%= f.label :password %>
<%= f.password_field :password, class: 'form-control' %>
<%= f.submit "Log In", class:"btn btn-primary" %>
<% end %>
</div>
</div>
</div>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(window).load(function(){
$('#myModal').modal('show');
});
</script>
When i include the code, the modal box will appear when i load the page. However, my modal still will not appear when i press the button. I do not understand why. It will only work when i include bootstrap.js in my /assets/javascripts folder. However, this affects my tab that i implement on my other page. I try loading just the bootstrap-modal.js file, but it did not work also. Please guide me on this.
Thanks