Creating inline date_select dropdowns using simple_form and zurb foundation - ruby-on-rails

I'm using Simple_Form with Zurb Foundation in my rails application.
One of more views has a form with the following date_select
The form fields are showing up stacked rather than inline. I've checked everything and can't figure out how to get these to show-up correctly.
What am I missing?
You can see the repo at https://github.com/stanrails/momtomom in the event.html.erb view.
The code for the section is below:
<div class="row">
<div class="small-5 columns">
<%= f.date_select :eventDate %>
</div>
</div>

One of the workaround is to have something manually like this:
form.custom .dropdown.date{
width: 30%;
margin-right: 10px;
float: left;
}

Here is another take on this I wanted to share which ends up looking like this:
A little html!
div[class="row"]
div[class="large-12 columns select-date-wrapper"]
= f.date_select(:birthdate,
options = { start_year: DateTime.now.year - 18, end_year: DateTime.now.year - 75, order: [:month, :day, :year], include_blank: true},
html_options = { class: 'select-date'})
A little sass!
select.select-date {
width: 30%;
margin-right: 10px;
float: left;
}
.select-date-wrapper{
select:first-of-type{
width: 45%;
}
select:nth-of-type(2){
width: 20%;
}
select:last-of-type{
margin-right: 0;
}
}

I solved the same problem by checking the html and changing the css of the relevant tags:
<%= f.date_select :date %> produces:
<div class="field col-md-6">
<select id="invoice_date_1i" name="invoice[date(1i)]">
<select id="invoice_date_2i" name="invoice[date(2i)]">
<select id="invoice_date_3i" name="invoice[date(3i)]">
</div>
With "Invoice" being the model name here. Therefore, in your css you can add
#yourModel_date_1i, #yourmodel_date_2i, #yourmodel_date_3i { width: 30%; }
for an easy fix.

Related

size option in gravatar_for helper, ruby on rails, not working

No matter what I put for the size option, the size remains the default 80 x 80. Any ideas why this might be?
<%= link_to gravatar_for(micropost.user, options = { size: 100 }), micropost.user %>
I thought there might be something in CSS that's overriding the parameter, but couldn't find anything:
.gravatar {
float: left;
margin-right: 10px;
}
.gravatar {
float: left;
margin-right: 10px;
}
img {
display: block;
padding: 5px 0;
}
I'd go about another aproach here if it is the https://github.com/mdeering/gravatar_image_tag gem you're using.
<%= link_to micropost.user do %>
<%= gravatar_image_tag('micropost.user', :gravatar => { :size => 15 }) %>
<% end %>
Try this:
<%= link_to gravatar_for(micropost.user, micropost.user), size: 100 %>
For more information on the usage of link_to helper method see RoR API here:
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
A snipet of your HTML code from browser's console would also be helpful here to help you better.

Using bootstrap glyphicon in rails simple form attachment

Hi all I use simple form. I have a model which contains attachment. Everything works fine except for I get a browse button in browser as shown in below image. Instead of Browse button I want bootstrap attachment glyphicon. How can I achieve this?. My code is below this image:
<%= simple_form_for Status.new do |f| %>
<%= f.input :status, as: :text, required: true, autofocus: true %>
<%= f.input :statachment, as: :file, label: 'Attach here' %>
<%= f.submit "Post", class: 'btn btn-primary' %>
<% end %>
You can try the following ways
http://markusslima.github.io/bootstrap-filestyle/
just need to add
<script type="text/javascript" src="js/bootstrap-filestyle.min.js"> </script>
Then
$(":file").filestyle({input: false});
or
<%= f.input :statachment, as: :file, label: 'Attach here', class: "filestyle", data-input: "false" %>
Or using another way
http://www.abeautifulsite.net/whipping-file-inputs-into-shape-with-bootstrap-3/
In Views
<span class="btn btn-default btn-file">
Browse <%= f.input :statachment, as: :file, label: 'Attach here' %>
</span>
and in css
.btn-file {
position: relative;
overflow: hidden;
}
.btn-file input[type=file] {
position: absolute;
top: 0;
right: 0;
min-width: 100%;
min-height: 100%;
font-size: 100px;
text-align: right;
filter: alpha(opacity=0);
opacity: 0;
outline: none;
background: white;
cursor: inherit;
display: block;
}

Simple form builder checkbox collection custom html input

With simple_form_for, how should one go about building something like a color selector? Imagine a page where the user can pick a number of colors to work with by checking checkboxes. I would like to present a little box with the color in it and a checkbox next to it so the user can pick the color by checking the check box. Something like this
<input type="checkbox" name="colors[test]"><div style="background-color: red; width: 20px; height: 20px"></div>
<input type="checkbox" name="colors[test]"><div style="background-color: green; width: 20px; height: 20px""></div>
<input type="checkbox" name="colors[test]"><div style="background-color: blue; width: 20px; height: 20px""></div>
You can add the html tags to the collection and define classes for each of them. And then style them accordingly. I am assuming you have a simple_form_for #color or something similar.
<%= f.input :test, :label => 'Choose a Color:', :collection =>{'<div class="red colorbox"></div>'.html_safe => 'red', '<div class="green colorbox"></div>'.html_safe => 'green', '<div class="blue colorbox"></div>'.html_safe => 'blue' }, :as => :check_boxes %>
In your stylesheet:
/* The colorbox will be under a label with collection_check_boxes class.*/
.collection_check_boxes {
width: 30px;
height: 20px;
}
.colorbox {
width: 20px;
height: 20px;
}
.red {background: red;}
.green {background: green;}
.blue {background: blue;}

Using Masonry in Rails - boxes not moving on window resize

I have tried this using both the files from the Masonry website, plus the masonry-rails gem, but am getting the same problem.
Basically, when I resize the browser window, the boxes aren't moving to fit the new page size. Instead, I'm just getting scroll bars appearing in the browser.
I know that the files are loading fine, and picking up the right selectors, because if I e.g. change the column width in the masonry() parameters, the boxes do appear in a different place when I load the page.
Also, I'm using Bootstrap if that's relevant, but I've named the selectors so they don't clash with the ones reserved for bootstrap - e.g. using #masonry-container instead of #container.
Any help would be much appreciated, thanks!!
application.js:
//= require masonry/jquery.masonry
message_board/show:
<div id="show-message-board">
<%= render :partial => "show_message_board", :locals => { :messages => current_user.messages }, :remote => true %>
</div>
<script>
$(function(){
$('#masonry-container').masonry({
// options
itemSelector : '.item',
columnWidth : 50,
isAnimated: true
});
});
</script>
_show_message_board.html.erb:
<div id="masonry-container" class="transitions-enabled infinite-scroll clearfix">
<% messages.each do |message| %>
<div class="item">
<p class="message_from"><%= message.user.first_name %> <%= message.user.last_name %>:</p>
<p class="message_content"><%= message.content %></p>
</div>
<% end %>
EDIT:
I've tried using the following as suggested elsewhere, and that still doesn't work!:
$(function(){
var $container = $('#masonry-container');
$container.imagesLoaded( function(){
$container.masonry({
itemSelector : '.item'
});
});
});
Here's what I did to get Masonry to work in my Rails project. Perhaps this will help you...
I downloaded the "jquery.masonry.min.js" file from the site and placed it in my app\assets\javascripts directory.
I added
//= require jquery.masonry.min to my application.js file
I created a separate css file for masonry (just to keep things neat) called "masonry.css.scss" under my app\assets\stylesheets directory. This is the CSS I have (I'm using "box" instead of your "item"):
.box {
margin: 5px;
padding: 5px;
background: #D8D5D2;
font-size: 11px;
line-height: 1.4em;
float: left;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
display: inline;
width: 260px;
}
.box img {
width: 100%;
}
Since I'm using the code in my "home\index.html.erb" file, I created a "home.js" file under my app\assets\javascripts" directory. This is the js code I have:
jQuery(document).ready(function () {
var $container = $('#UserShoppingRequestsContainer');
$container.imagesLoaded(function () {
$container.masonry({
itemSelector:'.box',
isAnimated:true,
animationOptions:{
duration:750,
easing:'linear',
queue:false
}
});
});
})
Finally, in my "home\index.html.erb" file, I have something like this:
<div id="UserShoppingRequestsContainer">
<% #shopping_requests.each do |shopping_request| %>
<div class="box col3" id="<%= shopping_request.id.to_s %>">
<%= link_to image_tag(shopping_request.request_picture.url(:medium)), user_shopping_request_path(shopping_request.user, shopping_request) %>
<p class="serif1_no_padding"><%= shopping_request.category.name %></p>
</div>
<% end %>
</div>
I think that's it.

will paginate coming out reversed

I'm using will paginate on my ruby on rails app..I've used this before on other apps and it was working fine however when i used it on this one for some reason it looks like the tabs for the pagination are reversed.
Here's the html
<div class="container">
<br />
<br />
<h2 class="black">
Recent News
<div class="line_section"><div>
</h2>
<div class="row">
<div class="span12">
<ul class="recent-news">
<% #news_all.each do |news| %>
<li style="font-size: 16px; line-height: 19px; letter-spacing: 1px; font-size: 14px; color: #555; text-align: left;">
<%= image_tag news.photo.url, class: 'pull-left', style: 'margin-right:40px; margin-top: 2px; width: 300px;' %>
<div style=" width: 600px; float: right;">
<%= link_to news.title, news %>
<br />
<%= link_to news.date, news, style: 'font-size: 10px; color: black; position: relative; top: 15px;' %>
<br /><br />
<%= truncate news.content, length: 500 %>
<br />
<%= link_to 'Read More...', news, style: 'font-size: 12px !important;' %>
</div>
</li>
<% end %>
<%= will_paginate #news_all %>
</div><!-- end span12 -->
</div><!-- end row -->
</div><!-- end container -->
here's the controller
def batnews
#article = Article.first
#news_all = News.all
#news_all = News.paginate(page: params[:page]).limit(4)
#comments = Comment.all
end
here's the link to the site so you can see what's actually going on.
http://www.batman-fansite.com/batnews
if you scroll to the way bottom you will see the pagination.
Fix you css:
.recent-news li {
float: right;
}
add something like
.recent-news .pagination li {
float: left;
}
There are two problems here:
Display order is incorrect due to CSS float:right, causing elements to go right in order rendered, which results in backwards order left-to-right.
Using limit(4) on paginated set vs. per_page: 4 option in pagination.
Check your CSS, you'll find:
.recent-news li {
float: right;
}
...and your controller code should be:
#news_all = News.paginate(page: params[:page], per_page: 4)
Try something like this:
def index
#posts = Post.paginate :page => params[:page], **:order => "created_at ASC"**
end

Resources