I'm building a Rails app with some filters in it using Ransack, and I wan't that the users are able to search a property using cards like in the image below. When they select a card in my DB that will return.
My Current Ransack form
<%= search_form_for #q, html: {autocomplete: 'off'} do |f| %>
<div class="container">
<div class="row">
<!--APARTMENT CARD-->
<div class="col l6 s6">
<div class="card-panel hoverable b-radius5px">
<img style="width:60px;" class="center" src="https://res.cloudinary.com/craftwebs/image/upload/v1584137944/condominium_pltgkr.svg" alt="">
<span class="center blue-grey-text text-lighten-2" style="margin-left: -15px;">Apartment</span>
</div>
</div>
<!--HOUSE CARD-->
<div class="col l6 s6">
<div class="card-panel hoverable z-depth-1 b-radius5px">
<img style="width:60px;" class="center" src="https://res.cloudinary.com/craftwebs/image/upload/v1584138119/real-estate_mugxx7.svg" alt="">
<span class="center blue-grey-text text-lighten-2">House</span>
</div>
</div>
<div class="center">
<%= f.submit "Search", class:" waves-effect blue-kafasa-bn waves-light btn b-radius15px" %>
</div>
Now, the only way Im able to search these properties is via select:
<div class="col l6 m6 s12">
<%= f.select(:propertytype_eq, options_for_select(['Apartment', 'Office', 'House' ]), {:include_blank => 'Pick a property'} ) %>
</div>
This is how it looks in my logs when I search for a specific property in my app using select:
Parameters: {"utf8"=>"✓", "q"=>{"price_gteq"=>"", "price_lteq"=>"", "propertytype_eq"=>"Apartment"}, "commit"=>"Search"}
How Can I make that the users search a property by using cards and not a select? Do I need to modify the materialize checkbox?
Did you try using onclick functions for the cards? You can add a onclick event that either initiates navigation or sets a flag/variable for the option you want.
Related
This code is one element of a gallery. The "a href" tag is crucial for making it possible to expand an image by clicking on it. It is important that I have "a href" otherwise the javascript plugin (magnific-popup) won't work.
<a href="app/assets/images/1-fullsize.jpg" class="portfolio-box">
<img src="app/assets/images/1-thumbnail.jpg" class="img-responsive" alt="">
<div class="portfolio-box-caption">
<div class="portfolio-box-caption-content">
<div class="project-category text-faded">
Category
</div>
<div class="project-name">
Project Name
</div>
</div>
</div>
</a>
So far I came up with this:
<a href="app/assets/images/1-fullsize.jpg" class="portfolio-box">
<%= image_tag("1-thumbnail.jpg", alt: "", :class => "img-responsive") %>
<div class="portfolio-box-caption">
<div class="portfolio-box-caption-content">
<div class="project-category text-faded">
Category
</div>
<div class="project-name">
Project Name
</div>
</div>
</div>
</a>
So the images are visible but the the expanding of the picture is obviously not working in Rails. I thought about implementing an link_to helper method inside a block. But I have no idea how I can use the link_to helper method, link it to a file and additionally giving it a class inside a block? Is there a different solution? Does someone have any hints? If you need further information just let me know?
How can I call a link_to helper method in a block, linking to an image file while using a class as well?
You can use the the image_path as second option of link_to.
In Example:
<%= link_to(image_path("1-fullsize.jpg"), class: "portfolio-box") do %>
<%= image_tag("1-thumbnail.jpg", alt: "", :class => "img-responsive") %>
<div class="portfolio-box-caption">
<div class="portfolio-box-caption-content">
<div class="project-category text-faded">
Category
</div>
<div class="project-name">
Project Name
</div>
</div>
</div>
<% end %>
http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/image_path
http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/image_tag
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
I'm trying to create a two column layout. The first side should span 9 columns and the next one 3. Inside the col-md-9 I want to nest two more columns, one that spans 4 and another one that spans 8.
<div class="row">
<% #huddles.each do |huddle| %>
<div class="col-md-9">
<div class="row">
<div class="col-md-4">
<img class="img-responsive" src="http://placehold.it/300x150">
</div>
<div class="col-md-8">
<h4><%= huddle.title %></h4>
<h4 class="huddle-description"><%= huddle.description %></h4>
<%= link_to "Read More...", huddle_path(huddle) %>
</div>
</div>
<% end %>
</div>
<div class="col-md-3">Second Column</div>
</div>
This however, comes out looking like this:
Am I nesting my rows and columns wrong? Or maybe it is my ruby code itself that screws up the layout once new "Huddles" are created?
EDIT: With the fixed code, the second column "col-md-3" comes out next to the last created huddle. Inspecting it, all the huddles make one single row.
<div class="row">
<% #huddles.each do |huddle| %>
<div class="col-md-9">
<div class="row">
<div class="col-md-4">
<img class="img-responsive" src="http://placehold.it/300x150">
</div>
<div class="col-md-8">
<h4><%= huddle.title %></h4>
<h4 class="huddle-description"><%= huddle.description %></h4>
<%= link_to "Read More...", huddle_path(huddle) %>
</div>
</div>
</div>
<% end %>
<div class="col-md-3">Second Column</div>
</div>
And looks like this, where the second column moves all the way down next to the last huddle created:
I think this is what you are going for. I am pretty confident the issue is with the html structure and has nothing to do with ruby.
I also want to clarify. The initial issue you were having was that you were starting a div inside the loop but only closing it outside the loop. So starting n amount of divs but only one closing tag, and that would cause it to look like the image you first posted.
<div class="row">
<div class="col-md-9">
<% #huddles.each do |huddle| %>
<div class="show-region" >
<div class="col-md-4" style="height:150px;">
<img class="img-responsive" src="http://placehold.it/300x150">
</div>
<div class="col-md-8" style="height:150px;">
<h4><%= huddle.title %></h4>
<h4 class="huddle-description"><%= huddle.description %></h4>
<%= link_to "Read More...", subjects_path(huddle) %>
</div>
</div>
<% end %>
</div>
<div class="col-md-3">Second Column</div>
</div>
Using the following HTML I am trying to randomly select one of the href links
<div class="field">
Check availability
</div>
</div>
</div>
</div>
</article>
</div>
<div class="views-row views-row-3 views-row-odd views-row-last">
<article id="node-cruise-47" class="node node-cruise node-search-result node-cruise-search-result node-published node-not-promoted node-not-sticky author-admin odd clearfix s-search-result" itemscope="" itemtype="http://schema.org/Product">
<div class="search-result-inner clearfix">
<div class="s-search-result--left">
<div class="s-search-result--middle">
<div class="s-search-result--right">
<div class="field field-name-field-price field-type-number-decimal field-label-inline clearfix price-summary">
<div class="field field-name-field-departure-duration field-type-number-integer field-label-hidden price-conditions primary-condition">Based on 7 nights, yacht only</div>
<div class="availability-button-wrapper-search">
<div class="field">
Check availability
Note that several href links are present on the page not just these 2. I am using the following code
b.links(:xpath => '//div[#class="field"]/a').click
However I get:
"undefined method `click' for #<Watir::AnchorCollection:0x2ba1858> (NoMethodError)"
Try to pick randomly from array
b.links(:xpath => '//div[#class="field"]/a').to_a.sample.click
I have a problem with multiples ajax forms in index view, only first works with remote: true attribute.
This is my index view with a forms
<% #mensagens.each do |mensagem| %>
<%= form_for(mensagem, remote: true,:authenticity_token => true) do |f| %>
<div class="row">
<div class="col-md-9">
<div class="widget">
<!-- BLOCK -->
<div class="row innerAll half border-bottom">
<div class="col-sm-12">
<div class="media-body">
<div class="innerAll half">
<div class='col-md-10'><%= f.number_field :avaliacao %></div>
<div class='col-md-2'><%= mensagem.slug %></div>
</div>
</div>
</div>
</div>
<div class="row innerAll half border-bottom">
<div class="col-sm-12">
<div class="media-body">
<div class="innerAll half">
<%= f.text_area :texto, :class=>"col-md-12 form-control", :placeholder=>"Mensagem" %>
</div>
</div>
</div>
</div>
<div class="row innerAll half border-bottom">
<div class="col-sm-12">
<div class="media-body">
<div class="innerAll half ">
<div class="col-md-2"><%= f.check_box :aprovado %></div>
<div class="col-md-2"><%= f.check_box :status %></div>
<div class="col-md-6 btn"><%= f.text_field :autor,:class=>"form-control", :placeholder=>"Autor" %></div>
<div class="col-md-2"><%= f.submit "Salvar", :class=>"btn btn-success" %></div>
</div>
</div>
</div>
</div>
<div class="row innerAll half border-bottom">
<div class="col-sm-12">
<div class='notyfy_wrapper mensagem_<%= mensagem.id %>'>
<div class="notyfy_message">
<span class="notyfy_text">
<div id="alerta"></div>
</span>
</div>
</div>
</div>
</div>
</div>
<!-- BLOCK -->
</div>
</div>
<% end %>
<% end %>
This is a result: (http://droido.com.br/html.html)
This first form works fine! but second, send a normal request (non-ajax) and redirect to show page!
At droido.com.br/mensagens the second form is nested inside the first. It appears the second This is why it isn't being set up with ajax, as forms are not supposed to be nested, so I expect Rails is not getting to it.
The problem is, based upon your code above, I am not finding any missing close tags. On the page it looks like the <div class='row'> is missing the closing tag. I suggest you knock out a section at a time until you find the problem. Or, delete the entire content and add back until you find it.
Have you used the Chrome dev tools? If not, try it out. Go to the web page, right click, inspect. It will show the tags in a hierarchical manner.
I am trying to place my text within a div class="span3" but it just displays as a long 1-line string in the browser.
<div class="container">
<div class="span3" style="padding-bottom:25px">
<%= link_to image_tag(illustration.image_thumbnail_url), illustration %>
</div>
<div class="span3">
<h4><%= illustration.name + " - " + illustration.source%></h4>
<p><%= illustration.description %></p>
</div>
</div>
Twitter Bootstrap system utilizes 12 columns grid. So, you must open a <div class="row"> and than you must have one or many spans - sum must be 12, for example:
<div class="row">
<div class="span4">...</div>
<div class="span8">...</div>
</div>
I don't really understand what you are trying to achieve, but you haven't open the <div class="row"> and the sum of your spans is not 12.
You might be able to open the row together with your container:
<div class="container row">
<div class="span6" style="padding-bottom:25px">
<%= link_to image_tag(illustration.image_thumbnail_url), illustration %>
</div>
<div class="span6">
<h4><%= illustration.name + " - " + illustration.source%></h4>
<p><%= illustration.description %></p>
</div>
</div>
EDIT - Try to do the interpolation in this way:
<%= "#{illustration.name} - #{illustration.source}" %>
You can also use html_safe to display the description:
<%= illustration.description.html_safe %>
Take a look in this guide: http://guides.rubyonrails.org/active_support_core_extensions.html#extensions-to-string