Adding a bootstrap glyphicon to a button in rails - ruby

I would like to add a user glyphicon to my login input box in a rails app i am currently using Rails 4.2.3 and Ruby 2.2.0
I have tried to search this for quite some time but have not found how to add this to a rails app and would like my code to remain ruby as much as possible and if at all possible (if not i suppose html will suffice but i would LOVE to learn how to do this in rails syntax.
any help would be appreciated.
my input field looks like this so far.
<div class="input-group input-group-lg">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
I would aslo like the glyph to appear on the Left and the placeholder on the Right of the input box if possible.

<%= button_tag raw("<i class='srch-control-icon-srch'></i> search"), class: "button round" %>

HTML
<div>
<div class="input-group">
<input type="text" class="form-control" placeholder="username" aria-describedby="basic-addon2"> <span class="input-group-addon" id="basic-addon2"> <span class="glyphicon glyphicon-log-out">
</span></span>
</div>
</div>
Fiddle Here

Related

Bootstrap select menu styling not combining with ruby

I have the following bit of code, I am trying to insert my ruby code into the select to create the standard drop-down selection. The code works however the styling it really shit.
<%= form.label :housing_size %>
<div class="field form-control form-group form-select pb-1">
<%= form.select :housing_size_id, options_from_collection_for_select(Housingsize.order(:value).all, "id", "value", current_user.id) %>
</div>
<p class=" open-text pt-1"> Please select a housing size </p>
image of styling issue i have

Values are not showing using Rails 3

I want to display data inside text field and those values will be fetched dynamically.But i am not getting any value(only blank filed is coming) when show action is executing.
Please check mu code given below.
Views/posts/show.html.erb
<p id="notice"><%= notice %></p>
<p>
<b>Name:</b>
<input type="text",value="<%= #post.name %>">
</p>
<p>
<b>Title:</b>
<input type="text",value="<%= #post.title %>">
</p>
<p>
<b>Content:</b>
<input type="text",value="<%= #post.content %>">
</p>
<%= link_to 'Edit', edit_post_path(#post) %> |
<%= link_to 'Back', posts_path %>
Please help me to resolve this issue.
Replace the value Property by removing quotes as:
<input type="text",value=<%= #post.content %>>

Accessing data from DB according to drop down selection using Rails 3

I have one doubt.I have a form which has two drop down field.when user will select option from first drop down list,accordingly all required value will fetch from db and set in second drop down list.Check my below code.
views/payments/payment.html.erb:
<div class="tbpaddingdiv2">
<%= form_for :payment,:url => {:action => "check_type" },remote: true do |f| %>
<div class="totalaligndiv">
<div class="input-group bmargindiv1 col-md-6 pull-left"><span class="input-group-addon text-left"><div class="leftsidetextwidth">Type :</div></span>
<%= f.select(:s_catagory,options_for_select([['Wood','Wood'],['Puja Samagree','Puja Samagree'],['Sweeper','Sweeper'],['Photo Grapher','Photo Grapher'],['Burning Assistant','Burning Assistant']],selected: "Type"),{},{:class => 'form-control'},{:onchange => ''}) %>
</div>
<div class="input-group bmargindiv1 col-md-6 pull-left"><span class="input-group-addon text-left"><div class="leftsidetextwidth">Select Vendor :</div></span>
<select class="form-control">
<option selected>Selected Vendor</option>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
</div>
<div class="clearfix"></div>
<div class="tbpaddingdiv1 text-center">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
<% end %>
</div>
controller/payments_controller.rb:
class PaymentsController < ApplicationController
def payment
#payment=Vendor.new
end
def check_type
#vendor=Vendor.find_by_s_catagory(params[:s_catagory])
end
end
Check my view page.There are two drop down menu.I can not complete this.First user will select value from first drop down menu.As soon as value will selected the data base search operation will start and all required value will fetched.The retrieved value will set in second drop down list.After that submit button will be clicked for other purpose.I am using Rails version 3.2.19.Please help me.
change your view, assign some class to vendor select div like:
.vendor_partial
= render partial: "select_vendors"
on select of s_catagory you will send ajax request to check_type and render returned #vendor in div for selected vendors,
in your check_type.js.haml file:
(".vendor_partial").html("#{escape_javascript(render partial: "select_vendors")}")
and _select_vendors.html.haml :
= collection_select(:vendor, :id, (#vendor.nil? ? [] : #vendor), :id, :vendor_name, prompt: "Select vendor")

Change value of Ruby variable in ERB file upon onclick

I want to change the value of a Ruby local parameter in my .erb file when a user clicks on a bit of text. (I am using Ruby with Sinatra, not Rails). The code looks like this:
<div class="modal-body">
<!-- Get ERB to work here -->
<p><i>No account? Register here</i></p> <!-- Should change new_user to true if clicked -->
<form class="input-group" style="margin: 0 auto" method="POST" action="/nanotwitter/v1.0/users/session">
<input class="form-control" type="text" name="username" placeholder="Username">
<br><br>
<input class="form-control" type="password" name="password" placeholder="Password">
<% if new_user %>
<br><br>
<input class="form-control" type="password" name="password2" placeholder="Repeat password">
<% end %>
<br><br>
<div class="input-group" style="margin: 0 auto">
<button type="button" class="btn btn-default form-control" style="width: 50%" data-dismiss="modal">Close</button>
<button class="btn btn-primary form-control" style="width: 50%" type="submit">
<% if new_user %>
Register
<% else %>
Log In
<% end %>
</button>
</div>
</form>
</div>
So obviously the Ruby code in the onlick attribute evaluates immediately, and I want it to only execute when the user clicks. I've searched this site and the internet, and I'm still not sure what the correct/standard implementation for this would be.
First, ruby dont interact with user events. Javascript does.
Second, what is new_user ? Simple variable? You want to use it to, say, swap forms for sign up\ sign in ? Or you want user to really register through this method?
If the case is to show sign in\ sign up form to user based oh his choice (new\registered), you should do it with only javascript.
In general, you should prepare markup for two different forms (register\login) and hide them according to some javascript variable, which user can choose.

submit action doesnt work in Rails 4

when I submitted the form, the new data don't save in database and as a result I can not see them, but when I make a new data like welcome= Welcome.new and welcome.title="your are" by rails console they work and I can only see things that I have made in console not by application. It seems submit bottom doesnt save any data.
new.html.erb
<h1> Submite </h1>
<form action="new" method="post" class="form-horizontal" role ="form">
<div class="form-group">
<label for"kind"> kind </label>
<input type="string" id="kind" name="kind" class="form-control">
</div>
<br>
<div class="form-group">
<label for"title"> title </label>
<input type="string" id="title" name="title" class="form-control">
</div>
<br>
<div class="form-group">
<label for"text">"text </label>
<input type="text" id="text" name="text" class="form-control">
<br>
</div>
<br>
</div>
<input type="submit" value="Submit" class="btn btn-primary">
List
</div>
index.html.erb
<% #welcomes.each do |welcome| %>
<li><%= welcome.title %> </li>
<% end %>
welcomes_controller
def index
#welcomes = Welcome.all
end
def new
#welcome = Welcome.new
end
def create
#welcome = Welcome.new(user_params)
if #welcome.save
flash.keep[:notice]="Successfuly created"
render :index
else
render :new
# format.json { render json: #user.errors, status: :unprocessable_entity }
end
end
private
def user_params
params.require(:welcome).permit(:kind, :title, :text)
end
Your form is not submitting to the right route. Use form builder instead:
<%= form_for #welcome do |f| %>
<%= f.label :kind %>
<%= f.text_field :kind %>
<%= f.submit %>
<% end %>
This will put right route for form submission into your HTML

Resources