我试图在创建项目时增加列并更新属性:
def items_create
@categories = Category.all
@item = Item.new(item_params)
@item.store_id = current_store.id
@item.update(account_id: current_store.account.id)
@search_suggestion = SearchSuggestion.where(term: [@item.title])
@search_suggestion.update_attributes(:items_count => +1 )
respond_to do |format|
if @item.save
format.html { redirect_to store_items_index_path(current_store), notice: 'Item was successfully created.' }
format.json { render :template => "stores/items/show", status: :created, location: @item }
else
format.html { render :template => "stores/items/new" }
format.json { render json: @item.errors, status: :unprocessable_entity }
end
end
end
Run Code Online (Sandbox Code Playgroud)
我找到了这个对象:
CACHE SearchSuggestion Load (0.0ms) SELECT "search_suggestions".* FROM "search_suggestions" WHERE "search_suggestions"."term" = 'Rolex' …Run Code Online (Sandbox Code Playgroud) 我有一个带有一些嵌套字段的注册表单,在这个表单中我添加了一个服务条款的复选框.
我正在尝试验证何时选中复选框,如果没有则返回错误.
validates_acceptance_of :agreement, :allow_nil => true, :accept => true, :on => :create
Run Code Online (Sandbox Code Playgroud)
我有一个布尔列,在accounts表中设置为默认值.
add_column :accounts, :agreement, :boolean, default: false
Run Code Online (Sandbox Code Playgroud)
此外,我已添加:agreement到允许的控制器参数.
这是形式:
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<div class="centerList">
<div id="error_explanation">
<%= devise_error_messages! %></div>
</div>
<div class="form-group">
<span class="asterisk_input"></span>
<%= f.email_field :email, autofocus: true, placeholder: "email", :class=>"form-control" %>
</div>
<div class="form-group">
<span class="asterisk_input"></span>
<%= f.password_field :password, placeholder: "password", autocomplete: "off", :class=>"form-control" %>
</div>
<div class="form-group">
<span class="asterisk_input"></span>
<%= f.password_field :password_confirmation, placeholder: "confirm password", autocomplete: …Run Code Online (Sandbox Code Playgroud) 来自views/plans/new.html.erb我得到的 plan_id 和价格参数如下:
<%= link_to "Sign up", new_store_registration_path(:plan_id => plan.id, :price => plan.price) %>\nRun Code Online (Sandbox Code Playgroud)\n\n然后应用程序重定向到注册页面,并使用以下内容保留之前的参数并添加电子邮件:
\n\n注册控制器.rb
\n\ndef after_sign_up_path_for(resource)\n new_transaction_path(session[:registration_params].merge(ema\xe2\x80\x8c\xe2\x80\x8bil: resource.email))\nend\n\ndef after_inactive_sign_up_path_for(resource)\n new_transaction_path(session[:registration_params].merge(ema\xe2\x80\x8c\xe2\x80\x8bil: resource.email))\nend\nRun Code Online (Sandbox Code Playgroud)\n\n最后注册后,应用程序重定向到views/transcation/new.html.erb,其中包含plan_id,price和email参数。
Parameters: {"ema\xe2\x80\x8c\xe2\x80\x8bil"=>"example@gmail.com", "plan_id"=>"bs96", "price"=>"150.0"}\nRun Code Online (Sandbox Code Playgroud)\n\n此时我正在尝试将电子邮件参数传递给交易<%= hidden_field_tag(:email, params["email"]) %>
但没有收到电子邮件,如下所示:
\n\nParameters: {"utf8"=>"\xe2\x9c\x93", "authenticity_token"=>"KeS2xK7NIJZwFQvW2kJKupcpURnQweq+yoRgk9AJ1aaOgFIIym4RKadI4jc6vYynMo4vKR4eLmdIynfBG+EusQ==", "email"=>"", "plan_id"=>"bs96", "amount"=>"150.0", "payment_method_nonce"=>"0c22f2fa-e212-0ad3-753b-0d183d02522b"}\nRun Code Online (Sandbox Code Playgroud)\n\n关于我做错了什么有什么想法吗???
\n\n更新1
\n\n在views/transcation/new.html.erb里面有ui和脚本中的braintree drop以及三个隐藏字段:
\n\n<div class="form-container radius-box glassy-bg small-10 small-centered medium-8 large-6 columns">\n <%= form_tag transactions_path do%>\n <div …Run Code Online (Sandbox Code Playgroud) 我正在尝试link_to一个网址,并希望在最后添加id.id在全局变量@id中:
<%= link_to "link", "https://www.example.com/sample-#{@id}" %>
Run Code Online (Sandbox Code Playgroud)
以上回复:
https://www.example.com/sample-#%3CItem:0x007fe66cf8e850%3E
Run Code Online (Sandbox Code Playgroud)
知道如何实现这个吗?