What's wrong with this line of code?
<%= submit_tag "Delete <i class='icon-check'></i>".html_safe, :disable_with => "Deleting", :class => "btn btn-danger"%>
This literally produces:
Evidently my html_safe call isn't doing anything.
Background:
I'm using Twitter Bootstrap as well as Font Awesome and I'm essentially trying to achieve a submit button with an icon inside of it.
To extend on Lukas' answer I needed a button tag rather than an input. This code produced the effect I was looking for:
<button type="submit" class="btn btn-danger">
Delete <i class="icon-check"></i>
</button>
Which resulted in:
I found the answer I was looking for here.
What's wrong with it? Submit button values should not contain embedded HTML code.
This is how submit button looks in HTML:
<input type="submit" value="Submit" />
HTML tags in value attributes are interpreted as text, not as HTML:
<input type="submit" value="<i>Submit</i>" />
<%= form.button :submit, class: 'btn btn-success' do %>
<i class="fa fa-plus"></i> Add Funder <i class="fa fa-chevron-right"></i>
<% end %>
This is good answer.
Related
I'm trying to get my task-manager app to render tasks stored in mongoDB via mongoose on my projects.ejs which contains three as follows:
<%- include("partials/taskCard", {taskState:"New task",}) %>
<%- include("partials/taskCard", {taskState:"In progress"}) %>
<%- include("partials/taskCard", {taskState:"Completed tasks"}) %>
I tried, rendering tasks individually using the value of the task state in the submit button, however, it only equates to "New task", even when other buttons are clicked
<button
class="btn task-submit-btn"
name="submitTaskButton"
value="<%= taskState %>"
type="submit"
>
ADD
</button>
Rendered task.
The code is available on Github
I have model with date time field after render new view and submit it all fields of model saved to database except date time field even I am using date time picker
Can any body help me to solve this problem
This is the code I am working on:
Interview controller
def new
#interview = Interview.new(:batch_id => #batch.id)
end
def create
#interview = Interview.new(interview_params)
# Save the object
if #interview.save
# If save succeeds, redirect to the index action
flash[:notice]= "تم إنشاء المقابلة بنجاح."
redirect_to(interviews_path(:batch_id => #batch.id))
else
# If save fails, redisplay the form so user can fix problems
render('new')
end
end
Interview new view code
<% #page_title = "إنشاء مقابلة" %>
<div id="content-header">
<div class='header-icon hr-icon'></div>
<h1>المقابلات</h1>
<div class='header-sep'>|</div>
<div class='sub-header'>إنشاء مقابلة</div>
<div id="inner-tab-menu">
<ul>
<li class='themed_bg themed-dark-hover-background'><%= link_to("<< العودة للجدول", interviews_path(:batch_id => #batch.id)) %></li>
</ul>
</div>
</div>
<div id="page-yield">
<div class="iterviews new">
<%= form_for(#interview, :url =>interviews_path(:batch_id => #batch.id)) do |f| %>
<%= render(:partial => 'form', :locals => {:f => f}) %>
<script type="text/javascript">
$(function () {
$('#datetimepicker1').datetimepicker();
locale: 'ar-sa'
});
</script>
<div><%= f.submit("إنشاء مقابلة", :class => 'submit_button') %></div>
<% end %>
</div>
</div>
form code
<div class="label-field-pair">
<div class="right-column">
<label for="student_grade">رقم المقابلة<span class="necessary-field">*</span> </label>
<div class="text-input-bg"><%= f.text_field(:code, style: "width: 240px;") %></div>
</div>
</div>
<div class="label-field-pair">
<div class="right-column">
<label for="student_grade">تاريخ المقابلة<span class="necessary-field">*</span></label>
<div class="text-input-bg" style="direction: ltr; margin: 0 10px 0 0;">
<div class='input-group date' id='datetimepicker1'>
<%= f.datetime_field(:interview_date , class: "form-control", style: "width: 200px;margin: 0;") %>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
<%= f.hidden_field(:batch_id, value: #batch.id) %>
I could find out the solution for this problem, of course the reason was that datetimepicker doesn't understand the values in my fields so what I did is the following:
1- change the numbers in moment-with-locales.js in the 'ar-sa' section from Indian numbers to Arabic numbers.
2- set the format: option to datetimepicker to match model attribute data type format in case it is date type or datetime type
and that's solve my problem
Does hanami support below code?
<%= form_for :question, routes.question_path. method: 'post' do %>
<div class="box-body">
<div class="row">
<div class="box-body pad">
<textarea id="content"></textarea>
</div>`enter code here`
</div>
</div>
<% end %>
And how can I can do it in my template?
Though this is possible, the official Hanami guide discourages it as it has to resort to monkey patching in order to work with the various template engines.
You can read more about it here.
An alternative approach is to define a single form rendering method in your view, like this:
def form
form_for :question, routes.questions_path, method: 'post' do
div(class: 'box-body') do
div(class: 'row') do
div(class: 'box-body pad') do
text_area :content, id: 'content'
end
end
end
end
end
Then, somewhere in your template, you can call it like this to render the form:
<%= form %>
And I'm supported by author the best way I want is:
<form action="<%= routes.question_path %>" method="POST">
<input type="hidden" name="_csrf_token" value="<%= csrf_token%>">
<!-- rest of the form goes here -->
</form>
Maybe it's help for someone else.
trying to incorporate nested sortable into my rails app.
I'm using Mongoid and the Ancestry gem, and I'm trying to make a page that updates the parent_id of a category on drag and drop with Nested-Sortable.
Been trying to experiment, but don't really understand what NestedSortable spits out in order to create a controller that will read it.
My controller has:
def sort
Category.update_all({parent_id: params[:parent_id].to_i})
render nothing: true
end
Routes:
resources :symbols, :as => :categories, :controller => :categories do
collection {post :sort}
end
Reorder.js.coffee:
jQuery ->
$('.reorder-tree').nestedSortable
handle: '.handle'
items: 'li'
toleranceElement: '> div'
update: ->
$.post($(this).data('update-url'), $(this).nestedSortable('serialize'))
And my reorder view spits out something like:
<ol class=reorder-tree>
<li id="category_513d372b10188f9b6b000014"><div>
<i class="icon-move handle"></i>
Chickne
<span class="btn-group show-on-hover">
<a href="/symbols/new?parent_id=chickne" class="btn btn-micro" data-remote="true" title="Add Sub-Category"><i class="icon-plus"></i>
</a>
<a href="/symbols/chickne/edit" class="btn btn-micro"><i class="icon-pencil"></i>
</a>
<a href="/symbols/chickne" class="btn btn-micro" data-method="delete" data-remote="true" rel="nofollow" title="Delete Category"><i class="icon-remove"></i>
</a>
</span>
</div>
<ol class="visible"><li id="category_513d373310188f9b6b000016"><div>
<i class="icon-move handle"></i>
Smoking Babies
<span class="btn-group show-on-hover">
<a href="/symbols/new?parent_id=smoking-babies" class="btn btn-micro" data-remote="true" title="Add Sub-Category"><i class="icon-plus"></i>
</a>
<a href="/symbols/smoking-babies/edit" class="btn btn-micro"><i class="icon-pencil"></i>
</a>
<a href="/symbols/smoking-babies" class="btn btn-micro" data-method="delete" data-remote="true" rel="nofollow" title="Delete Category"><i class="icon-remove"></i>
</a>
</span>
</div>
<ol class="hide"></ol>
</li>
</ol></li>
</ol>
Any help would be appreciated, thanks.
After seriously playing around with the array I was getting from Nested Sortable,
I was able to make this work by using this in my controller:
def sort
# html = "Env: #{Rails.env}. "
# infor = params[:category]
params[:category].each do |id, attr|
thisCat = params[:category][id]
#category = Category.where(:_id => id).first
# html << "ID= #{id} , thisCat= #{thisCat} Name= #{#category.name} Parent= #{#category.parent_id} ; "
unless thisCat == "null"
#category.parent_id = thisCat.to_s
#category.save
end
end
# flash[:alert] = html
# flash[:error] = infor
# render nothing: true
end
You can see what I commented out after I got it to work; that's all my debugging flash statements.
Cheers!
I'm brand new to rails (and coding in general) so I've a quick question on retrieving images from a database
Running rails 3.2.8
I have a list of products, code, description, price and product_image in the database, The product images is stored as 123.jpg in the database and the image itself is stored in app/assets/images folder
In my view I have the following code
<div class="center_content">
<div class="center_title_bar">Latest Products</div>
<% #camera_catalogues.each do |camera_catalogue| %>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title"><%= camera_catalogue.model_description %></div>
<div class="product_img"><%= link_to (image_tag camera_catalogue.product_image),camera_catalogue %></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price"><%=number_to_currency(camera_catalogue.price, :unit =>"€")%> </span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab">
<img src="assest/cart.gif" alt="" title="" border="0" class="left_bt" />
<img src="assest/favs.gif" alt="" title="" border="0" class="left_bt" />
<img src="assets/favorites.gif" alt="" title="" border="0" class="left_bt" />
details
</div>
</div>
Everything displays correctly except that the image is not retrieved from the database
which is this line
<div class="product_img"><%= link_to (image_tag camera_catalogue.product_image),camera_catalogue %></div>
Does the image in the database need to be saved with a different url. i.e. instead of 123.jpg it is saved as assets/123.jpg
or is there some other error in my code.
Help/advice greatly appreciated :)
Use it like this
<div class="product_img"><%= link_to (image_tag (camera_catalogue.product_image)),camera_catalogue %></div>
I guess it will work for you. You need not use 'assests/image_name'