Tag: 形成

如何使用Ruby on Rails 5将数据从URL拉入表单

我有一个表单,用户可以填写分享设计工作。 但是字段非常类似于dribbble.com。 我看到一些网站允许用户粘贴自动填写表单的链接。 可以在https://www.uplabs.com/submit上查看示例 我不需要如何做到这一点的确切代码。 你能指点一下方向吗? 一些插件,一些例子,……? 例; 填写表格(图片,标题,设计师ID,描述等)来自链接,如https://dribbble.com/shots/1902343-Subscribe-to-our-newsletters 谢谢!

Rails:更改params中属性的值

我有一个输入( price )的表单,用户填写的值如: 12,50或110,90 (法国价格)。 所以在控制器中我做: @quote = current_user.company.quotes.build!(params[:quote]) 问题是rails使用US方式的小数表示行为。 因此它以12.00或111.90的价格保存报价 那么如何告诉rails实际考虑欧洲版的小数? 谢谢。 UPDATE 解决方案是将此方法添加到Quote模型中。 def price=(data) write_attribute(:price, data.to_s.gsub(‘,’, ‘.’)) end 这将取代,用. 。 感谢Olivier提示。

Rails,MongoMapper在HAML中嵌套数组形成麻烦

我越来越 用于#的未定义方法`胡萝卜’ (引用ln#18) 尝试使用以下表单进行编辑时: = form_for @harvest do |f| – if @harvest.errors.any? #error_explanation %h2= “#{pluralize(@harvest.errors.count, “error”)} prohibited this harvest from being saved:” %ul – @harvest.errors.full_messages.each do |msg| %li= msg .field = f.label :created_at = f.text_field :created_at, :disabled => true %br = f.label :photo = f.text_field :photo %h2 Crops – @harvest.harvested_crops.each do |harvested_crop| = f.label :harvested_crop[‘crop’] […]

用于创建与嵌套模型的多对多关系条目的表单

我的应用程序包括以下五种模型: 超市可以有不同类别的产品,这些类别的产品可以由多个品牌生产。 现在我希望在我的超市 –forms中有一个(或两个) 选择字段,我可以在其中选择一个元素,其名称出现,一个或多个元素出现在Brand中,所以这可以存储在Origin中 。 我想我可以使用collection_select ,但我如何在这里使用它? class Supermarket :supplies end class Supply < ActiveRecord::Base belongs_to :origin belongs_to :supermarket end class Origin < ActiveRecord::Base belongs_to :category belongs_to :brand end class Category < ActiveRecord::Base has_many :origins end class Brand < ActiveRecord::Base has_many :origins end 也许,我还要调整模型…… 编辑 澄清表格的结果应该是: 在编辑超市的forms中,我想选择一个类别的产品和相应的品牌,以便我知道在这个特定的超市中销售此类别中的哪个类别和哪些品牌 : 超市(表格): 超市名称: 沃尔玛 类别 (选择一个): 可乐(Category_ID […]

Rails – 从单独的设置控制器编辑用户和配置文件模型

我正在努力弄清楚如何让它工作,但基本上我有2个模型: class User class Profile 一个用户有一个配置文件。 我还有一个带有“配置文件”和“更新”操作的SettingsController: class SettingsController < ApplicationController def profile @profile = User.find_by_id(current_user).profile end def update set_profile respond_to do |format| if @profile.update(profile_params) format.html { redirect_to @profile, notice: 'Profile was successfully updated.' } else format.html { render :edit } end end end private def profile_params params.require(:profile).permit(:name) end end 和/ settings / profile页面: Settings […]

nested_form没有保存到模型Rails 3

虽然我无法将表单数据保存到模型中,但我认为我正处于以下方面。 我有2个型号 class Prediction < ActiveRecord::Base attr_accessible :home_team, :away_team, :home_score, :away_score, :fixtures_attributes has_many :fixtures accepts_nested_attributes_for :fixtures end class Fixture < ActiveRecord::Base attr_accessible :home_team, :away_team, :fixture_date, :kickoff_time belongs_to :predictions end 为了创建一个新的预测记录,我有一个表单可以获取所有的灯具并预先填充表单,用户只需在每个团队旁边添加分数 <%= f.fields_for :fixtures, @fixtures do |ff| %> VS 然后我让我的控制器来处理新的/创建动作,我认为这是我可能会摔倒的地方 class PredictionsController ‘Predictions Submitted Successfully’ else render ‘new’ end end end 最后我的路线 resources :predictions resources :fixtures […]

Rails:DropDown选择控制器操作

美好的一天,我有这个表单视图/ startseites / index.html.erb,我在我的people_controller中指定了一个方法,她没有去。 我准备了一些幽灵代码来理解。 我想将带有button_to标记的下拉列表中的条目提供给控制器操作checkValid。 我想要根据数据库validation条目。 我必须从表中读取和写入。 我希望它足够清楚。 class PeopleController < ApplicationController def checkValid @trainerName = params[:trainer_name] @sportlerName = params[:sportler_name] @trainerPID = params[:trainer_pid] @sportlerPID = params[:sportler_pid] #checks if sportlerID is null @person = Person.find(params[:sportler_pid]) id = Person.sportler_id if id = nil then Person.sportler_id = params[:trainerPID] else puts "Sportler can have only one Trainer!" end […]

无法通过Rails 5应用程序中的表单创建新记录

这个表格工作得很好,但是我已经有一段时间没用过它了,我确定我在某个地方引入了一个错误,但我无法追踪它可能是什么。 我有两个其他类似的表单,按预期提交到相同的postgres数据库。 我可以编辑现有的记录,所以看起来它只是我遇到问题的新/创建方法。 日志实际上没有显示任何错误,它只是重定向回新视图: Processing by CoffeeshopsController#new as HTML Rendering coffeeshops/new.html.erb within layouts/application Rendered users/shared/_links.html.erb (1.4ms) [cache miss] Rendered partials/_mainnav.html.erb (10.2ms) [cache miss] Rendered partials/_footer.html.erb (1.1ms) [cache miss] Rendered coffeeshops/new.html.erb within layouts/application (22.4ms) Completed 200 OK in 158ms (Views: 155.2ms | ActiveRecord: 0.0ms) Started GET “/coffeeshops/new?utf8=%E2%9C%93&authenticity_token=2A91tyxSfricbX03rLRcx9Vqm%2FuWQiZSgwwjmmScH3GrTe63RRBMTHs72%2F4cQaoXD5yC8jxY2GaRLgHvdhgCbg%3D%3D&coffeeshop%5Bname%5D=New+Coffee+Shop&coffeeshop%5Bsnippet%5D=Great+new+coffee+on+the+banks+of+the+thames&coffeeshop%5Bdesc%5D=lovely+coffee+shop+serving+Red+Brick+coffee&coffeeshop%5Barea%5D=central&coffeeshop%5Burl%5D=website.com&coffeeshop%5Bemail%5D=&coffeeshop%5Baddress%5D=&coffeeshop%5Bpostcode%5D=&coffeeshop%5Blocale%5D=central&coffeeshop%5Bphone%5D=123&coffeeshop%5Bimage_thumb_path%5D=photo.jpg&coffeeshop%5Bimage_path%5D=photo.jpg&coffeeshop%5Bbeans%5D=Red+Brick&coffeeshop%5Blong_black%5D=2.5&coffeeshop%5Btag_list%5D=tag&commit=Save+Coffeeshop” for 127.0.0.1 at 2017-06-12 17:46:34 +0100 Processing by CoffeeshopsController#new […]

在数据库中存储日期和费率

这种情况的最佳做法是什么? 我正在建立一个预订系统,我正在寻找捕获和存储用户信息的最佳方法。 每个资源都可以使用一天,最多可以占用任意数量的用户。 例如,假设这是一个最多可容纳5人的热气球。 我希望我的表单看起来像这样: [Buttons to select # of guests] // So if a user wants the same price for 1-3 people he only has to enter it once. From [START DATE] to [END DATE]: [RATE] // Where the []’s are input fields for the user 我计划将每个价格存储在数据库中: Date, # of guests, rate 每个日期都有一行。 所以我需要将“ […]

如何让nested3中的nested_attributes工作?

这是我的用户模型: class User :destroy accepts_nested_attributes_for :teacher, :allow_destroy => true attr_accessible :email, :password, :password_confirmation, :remember_me, :teacher_attributes end 这是我的老师模型: class Teacher < ActiveRecord::Base belongs_to :user attr_accessible :user_id, :first_name, :last_name validates_presence_of :user_id, :first_name, :last_name end 这是我的表格: registration_path(:user)) do |user| %> 除了这个东西不会“接受嵌套属性”我的开发日志说: WARNING: Can’t mass-assign protected attributes: teacher 我不知道它是否相关,但表单不是在teacher_attributes数组中生成字段或任何东西 – 它在教师内部。 我猜这是我的问题所在,但我不知道如何把它放在里面。 请帮忙。 谢谢!