我有一个静态字符串变量,我需要根据HTTP协议进行更改.
更改静态字符串变量>是不好的做法
static string QuoteWebServiceUrl = CommonFunctions.ReadAppSetting("QuoteWebServiceUrl");
if(url == "https")
{
QuoteWebServiceUrl = CommonFunctions.ReadAppSetting("QuoteWebServiceUrlSecure");
}
else
{
QuoteWebServiceUrl = CommonFunctions.ReadAppSetting("QuoteWebServiceUrl");
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我试着用一段时间来使用simple_form来创建下面的例子但是+标签并修复了一些样式.任何人都知道如何解决:

结果来自以下代码:
.clear
= f.label "Gender"
= f.collection_radio_buttons(:gender, [['Male', 'icon_male'], ['Female', 'icon_female']],
:first, :last,
:item_wrapper_class => 'horizontal',
) do |gender|
= gender.label { image_tag("/assets/icons/16x16/#{gender.text}.png") + gender.radio_button }
.clear
.ruler
Run Code Online (Sandbox Code Playgroud) 当我使用rails时,我使用简单的表单gem创建一个简单的表单
我创建了一个这样的表单
<%= simple_form_for @user do |f| %>
<%= f.input :username %>
<%= f.input :password %>
<%= f.button :submit %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
但我想在每个字段旁边添加一个默认的图像元素.我怎么能实现这一目标?
我试试这个
<%= simple_form_for @user do |f| %>
<%= f.input :username % >
<img xxxx>
<%= f.input :password %>
<img xxxx>
<%= f.button :submit %>
<img xxxx>
<% end %>
Run Code Online (Sandbox Code Playgroud)
但我不会工作,因为它将包装为每个元素字段的新行.
我有一个使用simple_form gem创建的表单,它使用嵌套属性填充2个模型.我想检查是否有任何错误并显示一个新块.但是,我不确定如何正确访问模型location属性的错误消息Booking.
class Booking < ActiveRecord::Base
belongs_to :customer
attr_accessible :date_wanted, :location
end
Run Code Online (Sandbox Code Playgroud)
和
class Customer < ActiveRecord::Base
has_many :bookings
accepts_nested_attributes_for :bookings
attr_accessible :name, :phone, :bookings_attributes
validates_presence_of :name, :phone
end
Run Code Online (Sandbox Code Playgroud)
表格视图:
simple_form_for @customer, {:html => { :class => "form-horizontal" }} do |f|
= f.input :name
= f.input :phone
= f.simple_fields_for :bookings do |b|
= b.input :date
= b.input :location
- if @customer.errors[:appointments_attributes][:location]
# insert code if any validation errors for the date field were found
= f.button …Run Code Online (Sandbox Code Playgroud) error-handling haml ruby-on-rails ruby-on-rails-3 simple-form
我正在尝试使用simple_form通过复选框实施员工经常性扣减表.我的代码有效,但所选的经常性扣除不会保存在我的表格中.我无法理解为什么.
这是我的模特.
class Employee < ActiveRecord::Base
belongs_to :club
has_many :employee_recurrents
has_many :recurrents, :through => :employee_recurrents
end
class Recurrent < ActiveRecord::Base
belongs_to :club
has_many :employee_recurrents
has_many :employees, :through => :employee_recurrents
end
class EmployeeRecurrent < ActiveRecord::Base
belongs_to :employee
belongs_to :recurrent
end
Run Code Online (Sandbox Code Playgroud)
移民
class CreateEmployeeRecurrents < ActiveRecord::Migration
def change
create_table :employee_recurrents, :id => false do |t|
t.references :employee
t.references :recurrent
end
add_index :employee_recurrents, [:employee_id, :recurrent_id]
add_index :employee_recurrents, [:recurrent_id, :employee_id]
end
end
Run Code Online (Sandbox Code Playgroud)
形成
<%= simple_form_for @employee, html: {class: 'form-horizontal' } do |f| %>
<%= …Run Code Online (Sandbox Code Playgroud) 无论如何移动提示组件使其出现在输入之前?
当前显示的组件按以下顺序显示:标签,输入,提示,错误.我尝试添加:components选项,但这不起作用.
这是我的代码:
<%= f.input :content,
:components => [:label, :hint, :input],
:as => :text,
hint: 'Please 1) include your exact copy here, 2) upload your copy document in the next step, or 3) describe any content services to include in our estimate.',
required: true,
:label => "Copy" %>
Run Code Online (Sandbox Code Playgroud) simple_form在输入字段上为任何整数属性生成"type ='number'",而不是type ='text'.由于这会导致Chrome显示计数器控件,我宁愿只使用type ='text'作为数字的默认值.
似乎可以覆盖config/intializers/simple_form.rb中的默认值,但是从文档中不清楚如何准确地执行此操作.将数字列/属性设置为type ='text'的语法是什么?
我已经看过关于如何创建自己的生成器的rails演员,并且已经阅读了许多堆栈溢出问题.基本上我要做的是构建一个像内置的rails迁移生成器一样的生成器,它接受类似的参数attribute:type然后根据需要插入它们.这是我现在为我的发电机编写的代码.
class FormGenerator < Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
argument :model_name, :type => :string
argument :attributes, type: :array, default: [], banner: "attribute:input_type attribute:input_type"
argument :input_types, type: :array, default: [], banner: "attribute:input_type attribute:input_type"
def create_form_file
create_file "app/views/#{model_name.pluralize}/_form.html.erb", "
<%= simple_form_for @#{model_name.pluralize} do | f | %>
<%= f.#{input_type} :#{attribute}, label: '#{attribute}' %>
<% end %>
"
end
end
Run Code Online (Sandbox Code Playgroud)
基本上我想要它做的是生成一个视图文件,其中包含与参数一样多的行.因此传递rails g form products name:input amount:input other_attribute:check_box会生成一个_form.html.erb包含以下内容的文件:
<%= simple_form_for @products do | f | %>
<%= f.input :name, …Run Code Online (Sandbox Code Playgroud) 我有一个Profile模特,那个accepts_nested_attributes_for :grades.
我的Grade模型看起来像这样:
# == Schema Information
#
# Table name: grades
#
# id :integer not null, primary key
# subject :string
# result :string
# grade_type :integer
# profile_id :integer
# created_at :datetime not null
# updated_at :datetime not null
class Grade < ActiveRecord::Base
belongs_to :profile
enum grade_type: { csec: 0, cape: 1, sat: 2, g7: 3, g8: 4, g9: 5, g10: 6, g11: 7, g12: 8, g13: 9 }
end
Run Code Online (Sandbox Code Playgroud)
在我 …
使用 Simple Form gem 和 bootstrap,我试图找出一种方法 - 使用 Ruby - 以问号的形式在表单标签旁边添加一个工具提示,在悬停或单击时显示提示。我正在努力寻找任何相关信息来提供帮助。
我需要在下面的标准表单输入中添加什么?我尝试过很多事情,但似乎没有什么是接近的。
<%= f.input :phone, placeholder: "Phone Number" %>
Run Code Online (Sandbox Code Playgroud)
当我尝试以下操作时,不显示输入字段:
<%= f.input :phone, placeholder: "Phone Number" do %>
<span data-toggle='tooltip' title='We need your phone number because...'>?</span>
<% end %>
Run Code Online (Sandbox Code Playgroud)
非常感谢