我正在关注Spree deface覆盖开发人员指南:http://guides.spreecommerce.com/developer/deface_overrides_tutorial.html
我的代码完全匹配它们,但我一直收到这个错误.我环顾四周,但我没有看到其他人遇到这个问题或类似的东西:
Spree:模块的未定义方法`content_tag'
我正在运行Rails 4.0.2和ruby 1.9.3(有可能教程没有更新为rails 4?)
这是我的代码:
应用程序/重写/ add_sale_price_to_product_edit.rb
Deface::Override.new(:virtual_path => 'spree/admin/products/_form',
:name => 'add_sale_price_to_product_edit',
:insert_after => "erb[loud]:contains('text_field :price')",
:text => "
<%= f.field_container :sale_price do %>
<%= f.label :sale_price, raw(Spree.t(:sale_price)) %><span>*</span>
<%= f.text_field :sale_price, :value =>
number_to_currency(@product.sale_price, :unit => '') %>
<%= f.error_message_on :sale_price %>
<% end %>
")
Run Code Online (Sandbox Code Playgroud)
应用程序/模型/大礼包/ product_decorator.rb
module Spree
Product.class_eval do
delegate_belongs_to :master, :sale_price
end
end
Run Code Online (Sandbox Code Playgroud) 我已经按照Railscast将应用程序迁移到Rails 4并转换为Strong Parameters.http://railscasts.com/episodes/415-upgrading-to-rails-4
我的创建/新方法工作正常.但是,当我尝试更新记录时,我遇到了问题.我一直收到以下消息:
CustomersController中的ArgumentError #update未知密钥:first_name
我在Stack Overflow上查看了各种帖子,还生成了一个新的Rails 4应用程序,以验证我是否正确地做事.我显然错过了一些东西.
这是更新方法的Controller代码:
def update
@customer = Customer.find(customer_params)
respond_to do |format|
if @customer.update(customer_params)
format.html { redirect_to @customer, notice: 'Customer was successfully updated.' }
format.json { head :ok }
else
format.html { render action: "edit" }
format.json { render json: @customer.errors, status: :unprocessable_entity }
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是我设置强大参数的地方:
private
def set_customer
@customer = Customer.find(params[:id])
end
def customer_params
params.require(:customer).permit(:first_name, :middle_initial, :last_name, :address1, :address2, :city, :state, :zip, :phone, :gender, :email, :membership_id, :date_of_birth)
end
Run Code Online (Sandbox Code Playgroud)
非常感谢任何帮助.
我有Heroku的问题.以下是日志文件:
2014-01-04T17:37:20.387988+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/postgresql_adapter.rb:774:in `exec_no_cache'
2014-01-04T17:37:20.387988+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:138:in `block in exec_query'
2014-01-04T17:37:20.387988+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:435:in `block in log'
2014-01-04T17:37:20.387988+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
2014-01-04T17:37:20.388346+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:430:in `log'
2014-01-04T17:37:20.388346+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:137:in `exec_query'
2014-01-04T17:37:20.388346+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/postgresql_adapter.rb:921:in `column_definitions'
2014-01-04T17:37:20.388346+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/postgresql/schema_statements.rb:174:in `columns'
2014-01-04T17:37:20.388346+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/schema_cache.rb:114:in `block in prepare_default_proc'
2014-01-04T17:37:20.388346+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/schema_cache.rb:56:in `yield'
2014-01-04T17:37:20.388346+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/schema_cache.rb:56:in `columns'
2014-01-04T17:37:20.388346+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/model_schema.rb:208:in `columns'
2014-01-04T17:37:20.388346+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/model_schema.rb:249:in `column_defaults'
2014-01-04T17:37:20.388346+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/locking/optimistic.rb:169:in `column_defaults'
2014-01-04T17:37:20.388568+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/core.rb:171:in `initialize'
2014-01-04T17:37:20.388568+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/inheritance.rb:27:in `new'
2014-01-04T17:37:20.388568+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/inheritance.rb:27:in `new'
2014-01-04T17:37:20.388568+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/devise-3.2.2/app/controllers/devise/sessions_controller.rb:8:in `new'
2014-01-04T17:37:20.388568+00:00 …Run Code Online (Sandbox Code Playgroud) 我在Rails 4应用程序中有以下一组收集路径:
resources :stats do
collection do
match 'mrr', via: [:get, :post]
match 'upgrades', via: [:get, :post]
match 'arpu', via: [:get, :post]
match 'arr', via: [:get, :post]
match 'ltv', via: [:get, :post]
end
end
Run Code Online (Sandbox Code Playgroud)
至少还有十几个这样的match线.
有没有办法压缩,所以我不再重复(特别是via方法选项)?
我的协会约有50%的工作..
我有三个表 - 用户,乐队和BandMmberships
我可以从我的视图中从两个表中提取数据库中的信息,它工作正常..
@ user.bands.each
当我在控制台中运行命令时,它会保存到band数据库和bandmemberships数据库中
user = User.first
user.bands.create(:name =>"sample")
但是,如果我在控制台中运行"preferred"命令,它将失败:
user = User.first
user.create_band(:name =>"sample")
NoMethodError:#User的未定义方法`create_band':0x007ff0b9182728
但是,如果我使用bands/new.html.erb形式,只有乐队保存在数据库中,但在关联表(bandmemberships)中没有任何内容.不知道在哪里看起来真的但我觉得我只是错过了一行代码来使它全部工作
主视图 views/users/show.html.erb
<% provide(:title, "My Dashboard") %>
<div class="row">
<div class="col-md-5">
<%= render @user %>
</div>
<div class="col-md-7">
<h4>You are in <%= @user.bands.count %> bands:</h4>
<% if @user.bands.any? %>
<% @user.bands.each do |band| %>
<p><%= render band %></p>
<% end %>
<% else %>
<div>
<h3>You are not in any bands.</h3>
<p>Click here to join a band</p>
</div>
<% …Run Code Online (Sandbox Code Playgroud) # routes.rb
resources :assets, only: [:new, :create, :delete]
# asset.rb
class Asset < ActiveRecord::Base
belongs_to :post
end
# rake routes
Prefix Verb URI Pattern Controller#Action
post_comments POST /posts/:post_id/comments(.:format) comments#create
new_post_comment GET /posts/:post_id/comments/new(.:format) comments#new
posts GET /posts(.:format) posts#index
POST /posts(.:format) posts#create
new_post GET /posts/new(.:format) posts#new
edit_post GET /posts/:id/edit(.:format) posts#edit
post GET /posts/:id(.:format) posts#show
PATCH /posts/:id(.:format) posts#update
PUT /posts/:id(.:format) posts#update
DELETE /posts/:id(.:format) posts#destroy
post_form POST /post_form(.:format) posts#form
root GET / posts#index
Run Code Online (Sandbox Code Playgroud)
没有路由显示assets,但我需要能够删除它们而不指定post_id,因为它们可以在没有帖子的情况下存在(为了能够在新帖子中上传文件和接收这些文件所必需的).
路线assets#new和assets#create工作正常,但不是assets#destroy(我得到一个错误说DELETE …
这听起来像一个简单的问题,但由于某种原因,我迷路了.
在我的用户个人资料页面中,我正在显示他们的所有帖子.如果他们有3个帖子,我想展示这样的东西.
1. Post one title
2. Post two title
3. Post three title
Run Code Online (Sandbox Code Playgroud)
所以它显示了帖子左边的数字.这不能是帖子的ID.有谁知道如何解决这个问题?
在控制器中,我想验证数据库中是否params存在查询中具有id的记录,但Project.find(params[:id]).present? 如果id不存在,则执行此类操作时会出错.
我该如何验证存在呢?
我想做这样的事情:
@residenciais, @comerciais = TipoImovel.all.split { |t| t.residencial? }
Run Code Online (Sandbox Code Playgroud)
问题是它@comerciais总是空的,因为它永远不会返回对象,因为条件是假的.
有没有更好的方法呢?
在我看来,我有:
<div class="item active">
<%= image_tag "2.jpg",size: "500x300", class: "no-resize" %>
<div class="carousel-caption">
Some tag.
</div>
</div>
<% @photos.each do |photo|%>
<div class="item">
<%= image_tag photo.attachment.url,size: "500x300",class: "no-resize" %>
<div class="carousel-caption">
Some tag.
</div>
</div>
<% end %>
Run Code Online (Sandbox Code Playgroud)
有没有DRYer完成这个的方法(因为我做的唯一改变是为第一张照片添加类'active')即我可以将第一个项放在循环中并检测第一次迭代吗?
ruby-on-rails-4 ×10
ruby ×4
activerecord ×1
associations ×1
erb ×1
heroku ×1
routes ×1
spree ×1
sql ×1