When I try to update a service and submit everything updates except the name that goes to the SQL query with the old value.
The edit form: https://i.stack.imgur.com/YSZuD.png
If I submit this I get this:
↳ app/controllers/services_controller.rb:133:in `block in update'
Service Exists? (5.4ms) SELECT 1 AS one FROM `services` WHERE `services`.`name` = 'Tratamento 2' AND `services`.`id` != 2 LIMIT 1
↳ app/controllers/services_controller.rb:133:in `block in update'
Service Exists? (3.9ms) SELECT 1 AS one FROM `services` WHERE `services`.`ref` = 'test' AND `services`.`id` != 2 LIMIT 1
↳ app/controllers/services_controller.rb:133:in `block in update'
Service Update (3.9ms) UPDATE `services` SET `services`.`ref` = 'test', `services`.`description` = 'test', `services`.`updated_at` = '2021-12-29 11:05:20.531023' WHERE `services`.`id` = 2
ref gets the new value but name search for "Tratamento 2" (Old value).
/services/_edit.html.erb
<%= turbo_frame_tag :edit_service_details do %>
<div data-controller="unblind-modal">
<div data-unblind-modal-target="background" data-popup-confirm-delete-target="background" class="modal-background" style="z-index: 9998;"></div>
<div data-unblind-modal-target="content" data-target-modal="edit_details" class="fixed inset-0 overflow-y-auto flex items-center justify-center m-6" style="z-index: 9999;">
<%= form_with model: #service, url: polymorphic_path([#service], { business_id: #service.business.id }), class: " relative w-full flex flex-col items-center justify-center overflow-auto bg-white rounded-lg max-w-screen-sm" do |form| %>
<div class="w-full sticky top-0 flex items-center">
<div class="mx-6 py-4 w-full flex justify-between items-center">
<h1 class="txt_heading text-neutral-100 text-neutral-80">Edit Details</h1>
<div data-action="click->unblind-modal#close" data-target-modal="edit_details" class="btn-secondary btn-md flex items-center w-9 px-0 justify-center">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M6 18L18 6M6 6l12 12"/>
</svg>
</div>
</div>
</div>
<div class="w-full h-auto flex flex-wrap md:flex-nowrap overflow-auto">
<div class="w-full overflow-auto">
<div class="px-6 pb-4 overflow-auto space-y-4">
<div class="space-y-1 w-full">
<%= form.label :ref, :Reference, class: "input-label" %>
<%= form.text_field :ref, placeholder: :reference, autofocus: true, class: "text-field input-md w-1/2" %>
<% unless #service.errors[:ref].empty? %>
<div class="flex space-x-1 ">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 text-error" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z" clip-rule="evenodd"/>
</svg>
<span class="txt_caption text-error ">The reference field <%= #service.errors[:ref].first %></span>
</div>
<% end %>
</div>
<div class="space-y-1 w-full">
<%= form.label :name, class: "input-label" %>
<%= form.text_field :name, placeholder: :name, autofocus: true, class: "text-field input-md w-full" %>
<% unless #service.errors[:name].empty? %>
<div class="flex space-x-1">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 text-error" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z" clip-rule="evenodd"/>
</svg>
<span class="txt_caption text-error ">The first name field <%= #service.errors[:name].first %></span>
</div>
<% end %>
</div>
<div class="space-y-1 w-full">
<%= form.label :description, class: "input-label" %>
<%= form.text_area :description, rows: 3, placeholder: :description, class: "text-field w-full" %>
<% unless #service.errors[:description].empty? %>
<div class="flex space-x-1">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 text-error" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z" clip-rule="evenodd"/>
</svg>
<span class="txt_caption text-error ">The last name
field <%= #service.errors[:description].first %></span>
</div>
<% end %>
</div>
</div>
</div>
</div>
<div class="w-full sticky bottom-0 flex items-center">
<div class="mx-6 py-4 w-full h-full flex justify-end items-center">
<%= form.submit "Save", class: "btn-primary btn-md", disabled: false %>
</div>
</div>
<% end %>
</div>
</div>
<% end %>
services_controller.rb
def update
respond_to do |format|
if #service.update(service_params)
flash.now[:success] = ["The Service " + #service.name + " was updated"]
format.turbo_stream {
render turbo_stream: [
turbo_stream.update("flash", partial: "flash"), #Show Notification
turbo_stream.update("show_service_" + #service.id.to_s, partial: "show", locals: { service: #service }),
turbo_stream.update("edit_service_details"),
turbo_stream.update("edit_service_categories"),
turbo_stream.update("edit_service_variants"),
]
}
else
flash.now[:error] = ["The Service " + #service.name + " had an error."]
format.turbo_stream {
render turbo_stream: [
turbo_stream.update("flash", partial: "flash")
]
}
end
end
end
service_params:
def service_params
params.require(:service).permit(:name, :description, :ref, :state,
service_per_categories_attributes: [:_destroy, :id, :service_category_id],
service_variants_attributes: [
:_destroy,
:id,
:name,
:state,
:price],
)
end
Related
I'm currently trying to render a partial with errors messages if when a form submission fails to create a tenant instance. Im using locals as described in the Rails documentation to pass variables to a partial.
controllers/tenants_controller.rb
def new
#unit = Unit.find(params[:unit_id])
#tenant = Tenant.new
end
def create
#unit = Unit.find(params[:unit_id])
#tenant = #unit.tenants.new(tenant_params)
if #tenant.save
redirect_to #tenant
else
Rails.logger.error('Unable to save Tenant')
render 'new'
end
end
In here im redirecting to the new template if the #tenant fails to be created. This should be adding errors to the #tenant
tenants/new.html.erb
<div class="py-6">
<div class="max-w-7xl mx-auto px-4 sm:px-6 md:px-8">
<h1 class="text-2xl font-semibold text-gray-900">
Let's add the tenant's information
</h1>
</div>
<div class="max-w-7xl mx-auto px-4 sm:px-6 md:px-8">
<!-- Replace with your content -->
<%= form_for [#unit, #tenant], html: { class: "space-y-8 divide-gray-200" } do |f| %>
<%= render 'errors', locals: { tenant: f.object } %>
<div class="space-y-8 divide-y divide-gray-200 sm:space-y-5">
<div class="pt-8 space-y-6 sm:pt-10 sm:space-y-5">
<div class="space-y-6 sm:space-y-5">
<div class="sm:grid sm:grid-cols-3 sm:gap-4 sm:items-start sm:border-t sm:border-gray-200 sm:pt-5">
<label class="block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2">
<%= f.label :first_name, 'First name' %>
</label>
<div class="mt-1 sm:mt-0 sm:col-span-2">
<%= f.text_field :first_name, value: "Albert", class: "block max-w-lg w-full shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm border-gray-300 rounded-md" %>
</div>
</div>
<div class="sm:grid sm:grid-cols-3 sm:gap-4 sm:items-start sm:border-t sm:border-gray-200 sm:pt-5">
<label class="block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2">
<%= f.label :last_name, 'Last Name' %>
</label>
<div class="mt-1 sm:mt-0 sm:col-span-2">
<%= f.text_field :last_name, value: "Terry", class: "block max-w-lg w-full shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm border-gray-300 rounded-md" %>
</div>
</div>
<div class="sm:grid sm:grid-cols-3 sm:gap-4 sm:items-start sm:border-t sm:border-gray-200 sm:pt-5">
<label class="block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2">
<%= f.label :last_name, 'Last Name' %>
</label>
<div class="mt-1 sm:mt-0 sm:col-span-2">
<%= f.text_field :last_name, value: "Terry", class: "block max-w-lg w-full shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm border-gray-300 rounded-md" %>
</div>
</div>
<div class="sm:grid sm:grid-cols-3 sm:gap-4 sm:items-start sm:border-t sm:border-gray-200 sm:pt-5">
<label class="block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2">
<%= f.label :email, 'Email' %>
</label>
<div class="mt-1 sm:mt-0 sm:col-span-2">
<%= f.text_field :email, value: "example#gmail.com", class: "block max-w-lg w-full shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm border-gray-300 rounded-md" %>
</div>
</div>
<div class="sm:grid sm:grid-cols-3 sm:gap-4 sm:items-start sm:border-t sm:border-gray-200 sm:pt-5">
<label class="block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2">
<%= f.label :phone_number, 'Phone' %>
</label>
<div class="mt-1 sm:mt-0 sm:col-span-2">
<%= f.text_field :phone_number, value: "(000)000-0000", class: "block max-w-lg w-full shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm border-gray-300 rounded-md" %>
</div>
</div>
<div class="sm:grid sm:grid-cols-3 sm:gap-4 sm:items-start sm:border-t sm:border-gray-200 sm:pt-5">
<label class="block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2">
<%= f.label :lease_start_date, 'Lease start date' %>
</label>
<div class="mt-1 sm:mt-0 sm:col-span-2">
<%= f.text_field :lease_start_date, value: "", class: "block max-w-lg w-full shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm border-gray-300 rounded-md" %>
</div>
</div>
<div class="sm:grid sm:grid-cols-3 sm:gap-4 sm:items-start sm:border-t sm:border-gray-200 sm:pt-5">
<label class="block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2">
<%= f.label :lease_end_date, 'Lease end date' %>
</label>
<div class="mt-1 sm:mt-0 sm:col-span-2">
<%= f.text_field :lease_end_date, value: "", class: "block max-w-lg w-full shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm border-gray-300 rounded-md" %>
</div>
</div>
<div class="sm:border-t sm:border-gray-200 sm:pt-5">
<div>
<%= f.label :notes, 'Add your notes & documents', class: "block text-sm font-medium text-gray-700" %>
<div class="mt-1">
<%= f.rich_text_area :notes, class: "shadow-sm focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 rounded-md" %>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="pt-5">
<div class="flex justify-end">
<%= link_to 'Cancel', unit_path(#unit), class: "bg-white py-2 px-4 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" %>
<%= f.submit "Save", class: "ml-3 inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" %>
</div>
</div>
<% end %>
<!-- /End replace -->
</div>
Here im passing tenant variable via the locals however it doesn't seem to be passing the variable to the partial errors in the line <%= render 'errors', locals: { tenant: f.object } %>
When the errors partial is rendered an error is raised.
tenants/_errors.html.erb
<% if tenant.errors.any? %>
<div class="rounded-md bg-red-50 p-4">
<div class="flex">
<div class="flex-shrink-0">
<!-- Heroicon name: mini/x-circle -->
<svg class="h-5 w-5 text-red-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.28 7.22a.75.75 0 00-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 101.06 1.06L10 11.06l1.72 1.72a.75.75 0 101.06-1.06L11.06 10l1.72-1.72a.75.75 0 00-1.06-1.06L10 8.94 8.28 7.22z" clip-rule="evenodd" />
</svg>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-red-800">
There were <%= tenant.errors.count %> errors with your submission
</h3>
<div class="mt-2 text-sm text-red-700">
<ul role="list" class="list-disc space-y-1 pl-5">
<% tenant.errors.full_messages.each do |error_message| %>
<li><%= error_message %></li>
<% end %>
</ul>
</div>
</div>
</div>
</div>
<% end %>
Any idea why
undefined local variable or method `tenant' for #<ActionView::Base
is being raised?
You are calling render incorrectly.
You have two options. You can call it like this:
<%= render partial: 'errors', locals: { tenant: f.object } %>
or like this:
<%= render 'errors', { tenant: f.object } %>
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.
Sorry for the messy post, my first time posting. I have been trying to get this collection submit to work, but every time I press create report button I have it goes back to the screen and puts out Unpermitted parameter: :hero_id in the rails server terminal.
Model
class Report < ApplicationRecord
validates :subject, presence: true, length: { minimum: 6, maximum: 100 }
validates :description, presence: true, length: { minimum: 10, maximum: 300 }
belongs_to :requester
has_and_belongs_to_many :heros
end
View/Form
<div class="container">
<div class="row justify-content-center">
<div class="col-10">
<% if #report.errors.any? %>
<h2>The following errors prevented the article from being saved</h2>
<ul>
<% #report.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
<% end %>
<%= form_with(model: #report, class: "shadow p-3 mb-3 bg-dark rounded", local: true) do |f| %>
<div class="form-group row">
<%= f.label :subject, class: "col-2 col-form-label text-light" %>
<div class="col-10">
<%= f.text_field :subject, class: "form-control shadow rounded", placeholder: "Subject of Report" %>
</div>
</div>
<div class="form-group row">
<%= f.label :description, class: "col-2 col-form-label text-light" %>
<div class="col-10">
<%= f.text_area :description, rows: 10, class: "form-control shadow rounded", placeholder: "Description of Issue" %>
</div>
</div>
<div class="form-group row">
<%= f.label :hero, class: "col-2 col-form-label text-light" %>
<div class="col-10">
<%= f.collection_select(:hero_ids, Hero.all, :id, :hero_name, {prompt: "Select a Hero"}, {:required => true}) %>
</div>
</div>
<div class="btn-toolbar p-2 mb-2 row justify-content-center">
<%= f.submit class: "btn btn-primary" %>
</div>
<% end %>
</div>
<div class="mb-3">
<%= link_to '[ Cancel and return to reports listing ]', reports_path, class: "text-info" %>
</div>
</div>
</div>
Controller
def report_params
#byebug
params.require(:report).permit(:subject, :description, hero_ids: [])
end
Console
(byebug) params.require(:report)
<ActionController::Parameters {"subject"=>"Test report", "description"=>"Test report", "hero_ids"=>"1"} permitted: false>
What I'm doing here is changing the opacity of the header and adding a searchbar when it reaches a waypoint (A bigger searchbar). It works, the problem here is that the change is only applied after I inspect the window and change between screen sizes.
Even a simple console log only happens after inspecting the windows
CoffeeScript
$(document).ready -> #The indentation is correct
if $('#hero-image').length > 0
$searchBarMin = $('header #search-bar-group')
$searchaBar = $('#big-search-bar')
$header = $('header')
$nearYou = $('#near-you')
$searchBarMin.hide()
$header.css({background: "linear-gradient(rgba(0,0,0,1), rgba(0,0,0,0.3))", position: "absolute" })
waypoint = new Waypoint({
element: $('#near-you'),
handler: (direction)->
console.log '!///////////////////'
if (direction == "down")
$searchBarMin.show()
$header.css({background: "linear-gradient(rgba(0,0,0,1), rgba(0,0,0,1))" })
else
$searchBarMin.hide()
$header.css({background: "linear-gradient(rgba(0,0,0,1), rgba(0,0,0,0.3))" })
})
Header html
<header id="header-logged-in" class="expanded row">
<div id="logo-container" class="small-6 small-push-3 medium-3 medium-push-0 large-2 columns">
<%= link_to root_path do %>
<%= image_tag("TA_logo01.png") %>
<% end %>
</div>
<div class="small-12 medium-3 large-1 text-center columns">
<h6><i><%= link_to "What is TattooAdvisor", what_is_tattoo_advisor_path %></i></h6>
</div>
<div id="search-bar-container" class="large-5 show-for-large columns" action='/search' >
<%= form_tag search_path, method: :get do %>
<div id="search-bar-group" class="row collapse">
<div class="small-9 medium-6 medium-push-2 large-7 large-push-3 columns">
<%= text_field_tag :query, params[:query], data: {autocomplete_source: Artist.order(:name).map{ |u| {id: u.slug, reference: u.reference,state: u.state, label: u.name, image: u.avatar.url(:thumb) }} + Parlour.order(:name).map{ |u| {id: u.slug, label: u.name, reference: u.reference, state: u.state, image: u.avatar.url(:thumb) }}}, class: "name_autocomplete_search input-group-field", placeholder: "Search for parlours and artists"%>
</div>
<div id="search-button" class="small-2 small-pull-1 medium-pull-2 large-pull-1 columns">
<%= submit_tag "Search", class: "button" %>
</div>
</div>
<% end %>
</div>
<div id="log-in-div" class="small-12 medium-6 large-4 menu-centered columns">
<ul class="menu dropdown large-pull-1" data-dropdown-menu>
<li>
<div class="small-6 medium-6 large-push-2 columns">
<%= avatar_profile_link current_user, "thumb", class: 'logged-in-picture' %>
</div>
<div class="small-6 small-pull-1 medium-6 large-pull-0 columns">
<h4><%= current_user.display_name %></h4>
</div>
<ul class="menu">
<li class="upper-pad">
<%= link_to "Profile", profile_standard_path %>
</li>
<% if current_user.has_role? :artist %>
<li class="upper-pad">
<%= link_to "Artist Profile", profile_artist_path %>
</li>
<% end %>
<% if current_user.has_role? :parlour %>
<li class="upper-pad">
<%= link_to "Parlour Profile", profile_parlour_path %>
</li>
<% end %>
<li id="premium-drop-down-li">
<b><%= link_to "Upgrade Account", subscription_path %></b>
</li>
<li class="upper-pad">
<%= link_to "Invite", new_invite_path %>
</li>
<li class="upper-pad">
<%= link_to "Log Out", destroy_user_session_path, method: :delete %>
</li>
</ul>
</li>
</ul>
<div class="small-5 small-pull-1 medium-1 medium-pull-3 large-pull-5 columns">
<%= link_to "Review", new_review_path, class:'button' %>
</div>
</div>
<div id="search-bar-container" class="small-12 columns hide-for-large" action='/search' >
<%= form_tag search_path, method: :get do %>
<div id="search-bar-group" class="row collapse">
<div id="search-bar" class="small-9 medium-6 medium-push-2 columns">
<%= text_field_tag :query, params[:query], data: {autocomplete_source: Artist.order(:name).map{ |u| {id: u.slug, reference: u.reference,state: u.state, label: u.name, image: u.avatar.url(:thumb) }} + Parlour.order(:name).map{ |u| {id: u.slug, label: u.name, reference: u.reference, state: u.state, image: u.avatar.url(:thumb) }}}, class: "name_autocomplete_search input-group-field", placeholder: "Search for parlours and artists"%>
</div>
<div id="search-button" class="small-2 small-pull-1 medium-pull-2 columns">
<%= submit_tag "Search", class: "button" %>
</div>
</div>
<% end %>
</div>
HomePage
<div class="row full-width">
<div class="small-12 columns">
<div id="hero-image" class="row expanded">
<div id="front-search-box" class="small-12 medium-6 medium-centered large-4 columns collapse">
<div class="text-center">
<h3><i>Tattoos are art<br>
Art is subjective</i></h3>
<h5>Find the right artist for your tattoo</h5>
</div>
<div class="input-group">
<%= render 'search_box' %>
</div>
</div>
</div>
</div>
</div>
<%= render partial: 'near_you' %>
SearchBox Partial
<div class="row collapse">
<div class="small-11 menu" action='/search' >
<%= form_tag search_path, method: :get do %>
<div id="big-search-bar" class="row collapse">
<div class="small-10 column">
<%= text_field_tag :query, params[:query], data: {autocomplete_source: Artist.order(:name).map{ |u| {id: u.slug, reference: u.reference,state: u.state, label: u.name, image: u.avatar.url(:thumb) }} + Parlour.order(:name).map{ |u| {id: u.slug, label: u.name, reference: u.reference, state: u.state, image: u.avatar.url(:thumb) }}}, class: "name_autocomplete_search input-group-field", placeholder: "Search for parlours and artists"%>
</div>
<div id="search-button" class="small-2 column">
<%= submit_tag "Search", class: "button" %>
</div>
</div>
<% end %>
</div>
Rails version: 4.2.6.
Turbolinks: 5.0.1
Foundation 6.3.
Waypoints (Latests version, installed with bower)
This is a css issue clashing with the way waypoint.js works.
First thing you need to change is remove the property height: 100% on body, but keep it on html.
html{
height: 100%; # not on body, just html
...
}
Then, your header position attribute needs to be fixed and not absolute.
header{
position: fixed; # not absolute
...
}
If you do all this it should work.
I have a search form with two drop down options with varieties (params[:variety_one], params[:variety_two]). Once submitted I want to display the results of both varieties if they only exist in the trial_id column. The variety_id column has multiple enteries per trial_id.
e.g
trial_id | variety_id
444 | 2300
444 | 2255
444 | 3450
445 | 2300
445 | 3450
446 | 2300
446 | 2255
446 | 5567
So if the user selected varieties 2300 and 2255 then it would only hit trial_id's 444 and 446 not 455 as variety 2300 only exists.
This is my controller so far.
def index
all = Result.select(:variety_id)
#variety = Variety.where(:variety_id => all).order('variety_name DESC')
#years = Result.select('DISTINCT year')
#regions = Region.all
#irrigations = Trial.select('DISTINCT irrigated').order('irrigated ASC')
end
def search
#comparison = Result.group(:trial_id).where(variety_id: [params[:variety_one], params[:variety_two]]).having('COUNT(*) = 2').joins(:trial).where('trials.irrigated' => params[:irrigated], 'year' => params[:year]).joins(:regions).where('sites.region_id' => params[:regions])
end
This is the error I am getting
Mysql2::Error: Column 'trial_id' in field list is ambiguous: SELECT COUNT(DISTINCT results.trial_id) AS count_distinct_results_trial_id, trial_id AS trial_id FROM `results` INNER JOIN `trials` ON `trials`.`trial_id` = `results`.`trial_id` INNER JOIN `trials` `trials_results_join` ON `trials_results_join`.`trial_id` = `results`.`trial_id` INNER JOIN `sites` ON `sites`.`site_id` = `trials_results_join`.`site_id` INNER JOIN `regions` ON `regions`.`region_id` = `sites`.`region_id` WHERE `results`.`variety_id` IN (2300, 2255) AND `trials`.`irrigated` IN (0, 1, 2) AND `results`.`year` IN (2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014) AND `sites`.`region_id` IN (1, 2, 3, 4, 5, 6, 7, 8) GROUP BY trial_id HAVING COUNT(*) = 2
If i remove the group(:trial_id) it works, but it grabs all the variety_id's selected.
Form
<% #options = ['Dryland', 'Irrigated', 'Semi-irrigated'] %>
<%= form_tag vpc_search_path do %>
<div class="row-fluid">
<div class="span2"></div>
<div class="span4" style="text-align: center; padding: 10px 0 10px 0;">
<h5 style="padding-bottom: 10px; text-align: center;">Select Variety One</h5>
<%= select_tag :variety_one, options_from_collection_for_select(#variety, "variety_id", "variety_name", :selected => "2300"), include_blank: false %>
</div>
<div class="span4" style="text-align: center; padding: 10px 0 10px 0;">
<h5 style="padding-bottom: 10px; text-align: center;">Select Variety Two</h5>
<%= select_tag :variety_two, options_from_collection_for_select(#variety, "variety_id", "variety_name", :selected => "2255"), include_blank: false %>
</div>
<div class="span2"></div>
</div>
<div class="row-fluid">
<div class="span12" style="text-align: center; padding: 10px 0 10px 0;">
<h5 style="padding-bottom: 10px; text-align: center;">Trial Type</h5>
<% #irrigations.each do |i| %>
<div class="checkbox inline"><%= check_box_tag 'irrigated[]', i.irrigated, true %>
<% if i.irrigated == 0 %> <%= #options[0] %> <% end %>
<% if i.irrigated == 1 %> <%= #options[1] %> <% end %>
<% if i.irrigated == 2 %> <%= #options[2] %> <% end %>
</div>
<% end %>
</div>
</div>
<div class="row-fluid">
<div class="span2"></div>
<div class="span4" style="text-align: center; padding: 10px 0 10px 0;">
<h5 style="padding-bottom: 10px; text-align: center;">Select Years</h5>
<% #years.each do |y| %>
<%= check_box_tag 'year[]', y.year, true %> <%= y.year %></br>
<% end %>
</div>
<div class="span4" style="padding: 10px 0 10px 85px;">
<h5 style="padding-bottom: 10px;">Select Regions</h5>
<% #regions.each do |r| %>
<%= check_box_tag 'regions[]', r.region_id, true %> <%= r.name %></br>
<% end %>
</div>
<div class="span2"></div>
</div>
<div class="row-fluid">
<div class="span12" style="text-align: center; padding-top: 10px;">
<%= submit_tag "Compare" %>
<% end %>
</div>
</div>
def index
results_ids = Result.pluck('variety_id') ## use pluck here
#variety = Variety.where(:variety_id => results_ids).order('variety_name DESC')
#years = Result.select('DISTINCT year') # do you really need an object here? pluck?
#regions = Region.all # ok, all, really? large table?
#irrigations = Trial.select('DISTINCT irrigated').order('irrigated ASC')
end
def search
#comparison = Result.group('results.trial_id')
.where(variety_id: [params[:variety_one], params[:variety_two]])
.having('COUNT(*) = 2').joins(:trial)
.where('trials.irrigated' => params[:irrigated], 'year' => params[:year])
.joins(:regions).where('sites.region_id' => params[:regions])
end
generally speaking, whenever you get column is ambiguous you got to attach table name with it in your request cause rails is not able to form the full request to database itself