- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试通过模态窗口(远程:true)进行设计注册,并在后端完成所有操作,并在发生某些验证错误时通过呈现 javascript 进行。到目前为止,我在路上,我的验证消息似乎工作正常,但直到我尝试上传图像时,我才收到未知格式错误页面。我已经尝试了一些东西,但由于我对 RoR 很陌生,所以我的想法走到了尽头。下面是我的 registration_controller、模态视图和屏幕截图。
我还没有成功注册对象,所以代码在这一点上可能包含一些问题,但现在描述的问题阻碍了我前进。
我将非常感谢对此的任何帮助。谢谢你,米罗斯拉夫。
class RegistrationsController < Devise::RegistrationsController
clear_respond_to
respond_to :js
def create
build_resource(resource_params)
child_class = params[:user][:user_type].camelize.constantize
resource.rolable = child_class.new(user_params(child_class.to_s.underscore.to_sym))
valid = resource.valid?
valid = resource.rolable.valid? && valid
if valid && resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
flash.keep(:notice)
sign_in(resource_name, resource)
render :js => "window.location = #{root_path.to_json}"
else
set_flash_message :notice, :inactive_signed_up, :reason => inactive_reason(resource) if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, location: after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
respond_to do |format|
format.js {render layout: false, content_type: 'text/javascript'}
end
end
end
private
def user_params(user)
if user.to_s == "non_profit"
params[:user][:non_profit].permit(:name, :ico, :non_profit_type_id, :description, :website, :representative, contact_attributes: [:first_name, :last_name, :email, :phone, image_attributes: [:image]], image: [:image])
else
params[:user][:customer].permit(:first_name, :last_name, :gender, :dob, :city)
end
end
def resource_params
params[:user].permit(:email, :password, :password_confirmation, :terms, :opt_in_correspondence, bank_account_attributes: [:number, :bank_code_id], address_attributes: [:street, :city, :postcode])
end
结束
<%
@address = resource.build_address
resource.rolable = "NonProfit".constantize.new if resource.rolable.nil?
@logo = resource.rolable.build_image
@contact = resource.rolable.build_contact
@picture = resource.rolable.contact.build_image
@account = resource.build_bank_account
%>
<div id="modal-nonprofit-registration" class="z-2000 modal-bg" style="display: block;">
<div class="modal-wrap" style="margin-top: 0px;">
<div class="modal">
<div class="modal-header full bg-main txt-white container-center semi-padding-bottom semi-padding-top relative">
<h3 class="no-margin size-large-r"><%= t(:register_nonprofit_title) %></h3>
<div class="absolute full-h wrap-cross semi-right top">
<div class="table full-h">
<div class="full-h full-w table-center">
<span id="registration-close" class="bg-cross table-center pointer"></span>
</div>
</div>
</div>
</div>
<!-- Modal body /-->
<div class="modal-body table-nr full-w modal-content bg-base col-wrap half-padding-top half-padding-bottom half-padding-left half-padding-right">
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), html: { data: {type: 'script'}, id: "register-nonprofit-form" }, remote: true, multipart: true, authenticity_token: true) do |f| %>
<%= f.input :user_type, :as => :hidden, :input_html => { :value => "NonProfit" } %>
<div class="row">
<div class="col-6">
<h3><%= t(:register_nonprofit_login_details_title) %></h3>
<div class="row">
<div class="col-12 img">
<%= f.input :email, as: :email, autofocus: true, :required => true, label: false, placeholder: t(:register_field_email) %>
</div>
</div>
<div class="row">
<div class="col-12 img">
<%= f.input :password, as: :password, autocomplete: "off", :required => true, label: false, placeholder: t(:register_field_password) %>
<span class="muted-hint"><%= t(:register_field_password_hint) %></span>
</div>
</div>
<div class="row">
<div class="col-12">
<%= f.input :password_confirmation, as: :password, autocomplete: "off", :required => true, label: false, placeholder: t(:register_field_password_confirmation) %>
</div>
</div>
</div>
<%= f.simple_fields_for :non_profit, resource.rolable do |np| %>
<%= np.simple_fields_for :contact, resource.rolable.build_contact do |c| %>
<div class="col-6 last">
<h3><%= t(:register_nonprofit_contact_details_title) %></h3>
<div class="row">
<div class="col-6">
<%= c.input :first_name, :required => true, label: false, placeholder: t(:register_field_firstname) %>
</div>
<div class="col-6">
<%= c.input :last_name, :required => true, label: false, placeholder: t(:register_field_lastname) %>
</div>
</div>
<div class="row">
<div class="col-12">
<%= c.input :email, as: :email, :required => true, label: false, placeholder: t(:register_field_email) %>
</div>
</div>
<div class="row">
<div class="col-12">
<%= c.input :phone, as: :tel, :required => true, label: false, placeholder: t(:register_field_phone) %>
</div>
</div>
<%= c.simple_fields_for :image, @picture do |i| %>
<div class="row">
<div class="col-12">
<%= i.input :image, as: :file, label: false, placeholder: t(:register_field_photo), :class => "file", input_html: { :id => 'contact-file-input', hidden: true } %>
<div class="custom_file_upload">
<input id="contact-file-text" type="text" class="file" placeholder="<%= t(:register_field_photo) %>" name="file_info">
<div class="file_upload" id="contact-file-upload">
</div>
</div>
</div>
</div>
<% end %> <!-- end of contact image field -->
</div>
<% end %> <!-- end of contact fields -->
<% end %> <!-- end of non profit fields -->
</div>
<div class="row">
<h3><%= t(:register_nonprofit_organization_details_title) %></h3>
<div class="col-6">
<%= f.simple_fields_for :non_profit, resource.rolable do |np| %>
<h4><%= t(:register_nonprofit_organization_details_basic_title) %></h4>
<div class="row">
<div class="col-12">
<%= np.input :name, :required => true, label: false, placeholder: t(:register_field_org_name) %>
</div>
</div>
<div class="row">
<div class="col-12">
<%= np.input :ico, :required => true, label: false, placeholder: t(:register_field_ico) %>
</div>
</div>
<div class="row">
<div class="col-12">
<%= np.select(:non_profit_category_id, options_for_select(NonProfitCategory.options_for_select), { :prompt => t(:register_nonprofit_types_prompt) }, { :class => "form-control" }) %>
</div>
</div>
<% end %> <!-- end of nonprofit fields -->
<%= f.simple_fields_for :bank_account, @account do |ba| %>
<div class="row">
<div class="col-8">
<%= ba.input :number, :required => true, label: false, placeholder: t(:register_field_account) %>
<span class="muted-hint"><%= t(:register_field_account_hint) %></span>
</div>
<div class="col-4">
<%= ba.select(:bank_code_id, options_for_select(BankCode.options_for_select), { :prompt => t(:register_nonprofit_codes_prompt) }, { :class => "form-control" }) %>
</div>
</div>
<% end %> <!-- end of bank account fields -->
<%= f.simple_fields_for :address, @address do |a| %>
<h4><%= t(:register_nonprofit_organization_details_address_title) %></h4>
<div class="row">
<div class="col-12">
<%= a.input :street, :required => true, label: false, placeholder: t(:register_field_street) %>
</div>
</div>
<div class="row">
<div class="col-8">
<%= a.input :city, :required => true, label: false, placeholder: t(:register_field_city) %>
</div>
<div class="col-4">
<%= a.input :postcode, :required => true, label: false, placeholder: t(:register_field_psc) %>
</div>
</div>
<% end %> <!-- end of address fields -->
</div>
<div class="col-6 last">
<h4><%= t(:register_nonprofit_organization_details_other_title) %></h4>
<!--<div class="muted-italic">Doporučujeme vyplnit</div>-->
<%= f.simple_fields_for :image, @logo do |i| %>
<div class="row">
<div class="col-12">
<%= i.input :image, as: :file, label: false, placeholder: t(:register_field_logo), :class => "file", input_html: { :id => 'nonprofit-file-input', hidden: true } %>
<div class="custom_file_upload">
<input id="nonprofit-file-text" type="text" class="file" placeholder="<%= t(:register_field_logo) %>" name="file_info">
<div class="file_upload" id="nonprofit-file-upload">
</div>
</div>
</div>
</div>
<% end %> <!-- end of nonprofit image field -->
<%= f.simple_fields_for :non_profit, resource.rolable do |np| %>
<div class="row">
<div class="col-12">
<%= np.input :website, as: :url, label: false, placeholder: t(:register_field_web) %>
</div>
</div>
<div class="row">
<div class="col-12">
<%= np.input :description, as: :text, :required => true, label: false, placeholder: t(:register_field_description), :input_html => { :rows => 15 } %>
<div class="remainChars"><span class="usedChars">0</span>/1000</div>
</div>
</div>
<% end %> <!-- end of nonprofit fields -->
</div>
</div>
<div class="row">
<div class="col-7">
<%= f.simple_fields_for :non_profit, resource.rolable do |np| %>
<div class="checkbox">
<%= np.input :representative, as: :boolean, :required => true, boolean_style: :inline, :input_html => { :checked => false }, label: t(:register_field_representative) %>
</div>
<% end %>
<div class="checkbox">
<%= f.input :terms, as: :boolean, :required => true, boolean_style: :inline, :input_html => { :checked => false }, label: ("#{t(:register_field_terms)} #{link_to t(:register_form_link_terms), legal_statements_path, :title => t(:register_form_link_terms), :class => 'underline capital'}").html_safe %>
</div>
<div class="checkbox">
<%= f.input :opt_in_correspondence, as: :boolean, boolean_style: :inline, :input_html => { :checked => true }, label: t(:register_field_subscribe) %>
</div>
</div>
<div class="col-5 last">
<input type="submit" class="submit last" value="Registrovat" name="">
</div>
</div>
<% end %>
</div>
<!-- end of modal body /-->
</div>
</div>
最佳答案
文件上传不适用于远程表单。您应该使用其他方式上传文件。
例如;
我的建议是使用 remotipart。
关于javascript - ActionController::UnknownFormat 在 RegistrationsController#create(设计),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33774952/
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 4年前关闭。 Improve this questi
.NET 框架:4.5.1 我在 Blend for visual studio 2015 中遇到一个奇怪的错误,我找不到它的来源。 如果我在 VS 中打开我的 WPF 解决方案,它会加载并运行良好。
我经常遇到这样的问题,与 Hierarchical RESTful URL design 非常相似 假设该服务仅提供用户上传文档。 POST, GET /accounts PUT, DELETE /a
在 Rails 应用程序中,我使用 devise 来管理我的用户,而我用来销毁 session 的链接不再有效。它正在工作,现在我添加了事件管理员,但没有。 我的链接是 :delete, :clas
我已经坚持了超过 24 小时,试图按照此处发布的其他解决方案进行操作,但我无法使其正常工作。我是 Rails 新手,需要帮助! 我想让我的/users/edit 页面正常工作,以便我可以简单地更改用户
Devise 在以下情况下不会使用户超时: 用户登录,关闭选项卡,然后在超时 + X 分钟内重新访问该 URL。用户仍处于登录状态。 如果选项卡已打开并且稍后刷新/单击,则超时可以正常工作。这意味着
我想使用这样的 slider 我希望该 slider 根据提供给它的值进行相应调整。到目前为止,我只能应用具有渐变效果的背景,但无法获得这种效果。请通过提供样式代码来帮助我。
您应该为每种方法创建一个请求/响应对象,还是应该为每个服务创建一个? 如果我在所有方法中使用它,我的服务请求对象中将只有 5 个不同的东西,因为我对几乎所有方法使用相同的输入。 响应对象将只有一个字典
我正在尝试在 REST 中对实体的附件进行建模。假设一个缺陷实体可以附加多个附件。每个附件都有描述和一些其他属性(上次修改时间、文件大小...)。附件本身是任何格式的文件(jpeg、doc ...)
我有以下表格: Blogs { BlogName } BlogPosts { BlogName, PostTitle } 博客文章同时建模一个实体和一个关系,根据 6nf(根据第三个宣言)这是无效的。
如果 A 类与 B、C 和 D 类中的每一个都有唯一的交互,那么交互的代码应该在 A 中还是在 B、C 和 D 中? 我正在编写一个小游戏,其中许多对象可以与其他对象进行独特的交互。例如,EMP点击
关于如何记住我与 Omniauth 一起工作似乎有些困惑。 根据这个wiki ,您需要在 OmniauthCallbacksController 中包含以下内容: remember_me(user)
设计问题: 使用 非线程安全 组件(集合,API,...)在/带有 多线程成分 ... 例子 : 组件 1 :多线程套接字服务器谁向消息处理程序发送消息... 组件 2 :非线程安全 消息处理程序 谁
我们目前正在设计一个 RESTful 应用程序。我们决定使用 XML 作为我们的基本表示。 我有以下关于在 XML 中设计/建模应用程序数据的问题。 在 XML 中进行数据建模的方法有哪些?从头开始然
我正在设计一个新的 XSD 来从业务合作伙伴那里获取积分信息。对于每笔交易,合作伙伴必须提供至少一种积分类型的积分值。我有以下几点:
设计支持多个版本的 API 的最佳方法是什么。我如何确保即使我的数据架构发生更改(微小更改),我的 api 的使用者也不会受到影响?任何引用架构、指南都非常有用。 最佳答案 Mark Nottingh
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 4 年前。 Improv
我想用 php 创建一个网站,其工作方式与 https://www.bitcoins.lc/ 相同。确实,就每个页面上具有相同布局但内容会随着您更改链接/页面而改变而言,我如何在 php 中使用lay
我有一个关于编写 Swing UI 的问题。如果我想制作一个带有某些选项的软件,例如在第一个框架上,我有三个按钮(新建、选项、退出)。 现在,如果用户单击新按钮,我想将框架中的整个内容更改为其他内容。
我正在尝试找出并学习将应用程序拥有的一堆Docker容器移至Kubernetes的模式和最佳实践。诸如Pod设计,服务,部署之类的东西。例如,我可以创建一个其中包含单个Web和应用程序容器的Pod,但
我是一名优秀的程序员,十分优秀!