I need to create an uneditable semicolon in Rails text field for a date.
For instance, the user can enter the hours and the minutes, while the semicolon already there and is not deletable.
<%= text_field_tag(:start_time, '', class: "timepicker four", size: 5,
maxlength: 5, placeholder: 'HH:MM', value:
#booking_item.start_time.strftime('%H') + ":"+
#booking_item.start_time.strftime('%M')) %>
Any solution for this in Ruby?
Thanks
Related
I have a kendo-dropdown list in which I want to localize the default text. Is there any way to escape the single curly brace required for [defaultItem]?
Already Tried [defaultItem]="{{'{ text: 'Product Line', value: null }'}}" gives Parser Error: Got interpolation ({{}})
home.component.html
<kendo-dropdownlist id="ddlProductLine" i18n-[defaultItem]="##productlinedefaultitem" [defaultItem]="{ text: 'Product Line', value: null }" [data]="productLines" textField="text"
valueField="value" [valuePrimitive]="true" [(ngModel)]="selectedProductLineId" class="gprListFacets"
(selectionChange)="getBrandsFacet($event)">
</kendo-dropdownlist>
messages.en.xlf
<trans-unit id="productlinedefaultitem" datatype="html">
<source>{ text: 'Product Line', value: null }</source>
<target>{ text: 'Product Line', value: null }</target>
</trans-unit>
Angular i18n should identify kendo-dropdownlist [defaultItem] and pick a match from translation .xlf file.
first of all, excuse me if my english is not always very good.
I have a problem with the each_with_index... When I show a project, I display the offers for this project. I have to make appear a banner in third position of offers, so I use each_with_index for that.
The problem is that: if I have sixteen offers on a project, I have sixteen times the entirely list of offers, and I don't know why.
This is my code:
- #offers.each_with_index do |offer, index|
- if !user_signed_in? && (#project.published? || #project.pending_attribution?)
- if #offers.size >= 3 && index == 3
= render 'offer_cta'
- contact_bloc = user_contact_bloc(offer.user, viewer: current_user, display_contact_info: offer.display_contact_info?)
.card.offer-card.mt-4[offer]{ class: offer_class(offer) }
.card-header.d-flex.justify-content-between.align-items-center.border-bottom-0
.offer-date
%span.text-muted
Offer filed on
= l(offer.created_at, format: '%d/%m/%Y à %Hh%M')
- if user_signed_in? && current_user.admin? && !offer.user.suspended_at.nil?
... exctera
Also, if I try this in my console, I don't have any problem...
Have you ever had this problem?
Don't hesitate to ask me if you need more information.
EDIT :
This is the code in my render 'offer_cta', a very basic code:
.row
.col-md-12
.project-cta.p-5.mb-2.text-center
%h5
%strong
blabla
%p.text-muted blablabla
%p.m-0
= link_to "Send a quote", "", class: "btn btn-primary px-3", data: { toggle: 'modal', target: '#modal-sign' }, onclick: "ga('send', 'event', 'button', 'Clic', 'Sign up');", tabindex: -1
#offers initialization:
#offers = #project.offers_accessible_by(current_ability, current_user)
#offers.mark_as_read_for(current_user)
#offers = #offers.includes(:offer_interactions, user: [:user_profile, :user_subscription, :user_contact])
I added this block to my deck.rb:
text(str: 'Gain 1 :tribute:') do |embed|
embed.svg key: ':tribute:', file: 'tribute.svg'
end
However, this puts "Gain 1 [my icon here]" into the top left of every card, but not where the card text says "Gain 1 tribute."
If I add this line, in an attempt to make it specify the "Ability" column in my .csv file:
%w(Ability).each do |key|
Then I get an error message:
"Syntax error, unexpected end-of-input, expecting keyword_end."
What do I need to add to my deck.rb, exactly, in order to make it use the tribute.svg icon wherever cards within the Ability column have the text, "Gain 1 tribute"?
Here's my current deck.rb:
require 'squib'
require 'game_icons'
Squib::Deck.new(cards: 4, layout: %w(hand.yml layout.yml)) do
background color: '#FFFFFF'
data = csv file: 'country.csv'
png file: data['Art'], layout: 'Art'
%w(Title Ability Quote Type Subtype).each do |key|
text str: data[key], layout: key, markup: true
end
%w(Tribute Power Dominion).each do |key|
svg file: "#{key.downcase}.svg", layout: "#{key}Icon"
text str: data[key], layout: key
end
text(str: 'Gain 1 :tribute:', x: 275, y: 745) do |embed|
embed.svg key: ':tribute:', file: 'tribute.svg'
end
save_png prefix: 'country_'
end
The text method needs to have x and y specified. Like this:
text(str: 'Gain 1 :tribute:', x: 300, y: 500) do |embed|
embed.svg key: ':tribute:', file: 'tribute.svg'
end
As for the syntax error, every do needs an end, because you're defining a block. Although that part seems unrelated to the first part of your question. The snipped %w(Ability).each seems silly to me because that's just iterating over a 1-element array.
I am trying to filter ActiveRecord_AssociationRelations to be unique by parent id.
So, I'd like a list like this:
[#<Message id: 25, posted_by_id: 3, posted_at: "2014-10-30 06:02:47", parent_id: 20, content: "This is a comment", created_at: "2014-10-30 06:02:47", updated_at: "2014-10-30 06:02:47">,
#<Message id: 23, posted_by_id: 3, posted_at: "2014-10-28 16:11:02", parent_id: 20, content: "This is another comment", created_at: "2014-10-28 16:11:02", updated_at: "2014-10-28 16:11:02">]}
to return this:
[#<Message id: 25, posted_by_id: 3, posted_at: "2014-10-30 06:02:47", parent_id: 20, content: "This is a comment", created_at: "2014-10-30 06:02:47", updated_at: "2014-10-30 06:02:47">]
I've tried various techniques including:
#messages.uniq(&:parent_id) # returns the same list (with duplicate parent_ids)
#messages.select(:parent_id).distinct # returns [#<Message id: nil, parent_id: 20>]
and uniq_by has been removed from Rails 4.1.
Have you tried
group(:parent_id)
It sounds to me like that is what you are after. This does return the first entry with the given parent_id. If you want the last entry you will have to reorder the result in a subquery and then use the group.
For me in Rails 3.2 & Postgresql, Foo.group(:bar) works on simple queries but gives me an error if I have any where clauses on there, for instance
irb> Message.where(receiver_id: 434).group(:sender_id)
=> PG::GroupingError: ERROR: column "messages.id" must appear in the
GROUP BY clause or be used in an aggregate function
I ended up specifying an SQL 'DISTINCT ON' clause to select. In a Message class I have the following scope:
scope :latest_from_each_sender, -> { order("sender_id ASC, created_at DESC").select('DISTINCT ON ("sender_id") *') }
Usage:
irb> Message.where(receiver_id: 434).latest_from_each_sender
We are trying to embed two simple form fields as columns in a table, we noticed that it takes about 4.5 seconds for simple fields to generate those tags. The table has 230 rows.
Performance with the simple_fields_for block commented out is .5 seconds, with simple fields for : 5 seconds
= simple_form_for :account,url: create_transactions_path, method: :put do |f|
%table.table.table-striped
......
........
........
%tbody
- loans_view = loans_view(#loans)
- loans_view.each do |lv|
- loan = lv[:loan]
- account = loan.account
.......
.......
%td
= lv[:amount_due]
= f.simple_fields_for :loan, index: loan.id do |al_f|
= al_f.simple_fields_for :account_transaction, index: account.id do |act_f|
%td
= act_f.input :amount, label: false, input_html:{value: account.top_up_amount}
%td
= act_f.input :include_for_update, as: :boolean, label: false, input_html: {checked: true}
We had enabled logging and made sure no db call goes out or any time consuming API is being called in the simple fields for block.