我最近将Rails 4.1应用程序升级到4.2.当我在开发模式下查看页面源时,所有资产现在都有与之关联的指纹:
/assets/application-7d90cdd9d3a3cc2a3445c0e8b748db14.js?body=1
Run Code Online (Sandbox Code Playgroud)
Pre 4.2我认为以前是
/assets/application.js?body=1
Run Code Online (Sandbox Code Playgroud)
有什么改变或我错过了配置设置?
我的代码昨天工作正常,然后我从git恢复了一些更改我得到了这个错误
/usr/local/lib/ruby/gems/2.2.0/gems/bundler-1.8.3/lib/bundler/runtime.rb:34:in `block in setup': You have already activated spring 1.3.4, but your Gemfile requires spring 1.3.3. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
Run Code Online (Sandbox Code Playgroud)
我不确定如何解决这个问题我已经在终端运行了bundle命令但仍然没有运气!请帮助MEEEE !!!!
我想将字符串product on sale转换ProductOnSale为模型名称.
怎么实现呢?
谢谢.
嗨我已经从rails 3.2.12升级到4.0.0大多数人认为现在工作正常,但是我收到了这个错误:

在这种情况下是什么问题?
我在我的应用程序中实现了几个不同的搜索表单,试图实现一个特定的操作(输入对象ID并直接进入该实例的Show Page),并且我对此问题非常接近,直到遇到Unsupported: Symbol运行时错误for Cards#Index.
这是搜索表单(我把它放入layouts/application.html.erb:
<%= form_tag(cards_path, :method => "get") do %>
<div class="input-append">
<%= text_field_tag :search, params[:search], class: "span2", placeholder: "Search Cards" %>
<button class="btn" type="submit"><i class="icon-search"></i></button>
</div>
<% end %>
Run Code Online (Sandbox Code Playgroud)
这是我的cards_controller.rb索引动作:
def index
if params[:search]
@cards = Card.search(params[:search]).order("created_at DESC")
else
@cards = Card.order("created_at DESC")
end
end
def show
end
private
def set_card
@card = Card.find(params[:id])
end
def card_params
params.require(:card).permit(:title, :description)
end
Run Code Online (Sandbox Code Playgroud)
和模型 card.rb
class Card < ActiveRecord::Base
validates :title, presence: true, uniqueness: …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的课:
class House
def bricks
Brick.for(@house_plan).where(size: 5)
end
def wood
Wood.for(@house_plan).where(size: 5)
end
end
Run Code Online (Sandbox Code Playgroud)
我的目标是提取电话 for(self).where(size: 5):
我首先尝试的是:
class House
def bricks
Brick.match_material
end
def wood
Wood.match_material
end
def match_material
for(@house_plan).where(size: 5)
end
end
Run Code Online (Sandbox Code Playgroud)
但后来我收到了这个错误:
syntax error, unexpected '\n', expecting :: or '[' or '.'
Run Code Online (Sandbox Code Playgroud)
然后我将我的代码更改为:
def match_material
.for(@house_plan).where(size: 5)
end
Run Code Online (Sandbox Code Playgroud)
现在我做的时候:
house = House.new(HousePlan.new)
house.bricks
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
formal argument cannot be an instance variable
Run Code Online (Sandbox Code Playgroud)
在这一行: for(@house_plan).where(size: 5)
请建议我正确的语法我希望用户应该是男性还是女性我无法找到它的正确用法.
这是我的表单,单击单选按钮时,两者都被选中并保持选中状态.我希望那个用户应该选择男性或女性.
<%= form_for @user do |f| %>
<div class="well-lg">
<h4>Personal Details</h4>
<div class="form-group">
<%= f.label :First_Name %><br />
<%= f.text_field :fname, :class=> 'form-control' %>
</div>
<div class="form-group">
<%= f.label :Last_Name %><br />
<%= f.text_field :lname, :class=> 'form-control' %>
</div>
<div class="form-group">
<%= f.label :Email_Address %><br />
<%= f.text_field :email, :class=> 'form-control' %>
</div>
<div class="form-group">
<%= f.label :Mobile_No%><br />
<%= f.text_field :mob, :class=> 'form-control' %>
</div>
<div class="form-group">
<%= f.label :Gender %> <br />
<%= f.label :Gender, 'male' %> …Run Code Online (Sandbox Code Playgroud) 我有一个cartridge和dosing_edge模型,他们分别有关系has_many和belongs_to.通过这样做我可以打电话:
@cartridge.dosing_edges
Run Code Online (Sandbox Code Playgroud)
检索属于盒式磁带的所有dosing_edges.这样可行,但墨盒模型也有一个dosing_edges属性.如何区分方法和属性.
我的意思是,如果我想访问@cartridge.dosing_edges不调用方法.dosing_edges来检索所有dosing_edges.
或者我应该将我的dosing_edges属性重命名为不同.
我的应用程序有products,categories和subcategries.我在网址/dash上有一个管理界面来编辑这些详细信息.我试着像这样设置网址:
/dash/products/products/porduct-code/category-name/dash/editcategories指向动作的类别编辑列表editcategoriescategory-name/subcategory-name/dash当我试图解决一件事时,另一件事打破了.我的整个路线文件变得一团糟.试图解决它们,事情不会奏效.这是我的路线文件:
Rails.application.routes.draw do
# Pages
root 'pages#home'
get 'terms' => 'pages#termsandconditions'
get 'delivery-charges' => 'pages#deliverycharges'
get 'search' => 'pages#search'
get 'deals' => 'pages#alldeals'
get 'contact', to: 'pages#contact'
post 'contact', to: 'pages#contactscreate'
get 'dealslist' => 'pages#dealslist'
get 'cart' => 'carts#cart'
get 'rate' => 'districtrates#rate'
get 'deliverycharges' => 'districtrates#deliverycharges'
get 'pricecalc' => 'pages#pricecalc'
# Devise routes
# Others
resources …Run Code Online (Sandbox Code Playgroud) accepts_nested_attributes_for创建重复项
模型
class Article < ActiveRecord::Base
has_many :article_collections
accepts_nested_attributes_for :article_collections, :allow_destroy => true, reject_if: :all_blank
end
class ArticleCollection < ActiveRecord::Base
belongs_to :article
end
Run Code Online (Sandbox Code Playgroud)
调节器
def update
@article = Article.find_by_id(params[:id])
@article.update_attributes(params[:article])
redirect_to :index
end
Run Code Online (Sandbox Code Playgroud)
PARAMS
params = {"utf8"=>"?"
"article"=>
{
"data_id"=>"dfe9e32c-3e7c-4b33-96b6-53b123d70e7a", "name"=>"Mass", "description"=>"mass",
"status"=>"active", "volume"=>"dfg", "issue"=>"srf", "iscode"=>"sdg",
"image"=>{"title"=>"", "caption"=>"", "root_image_id"=>""},
"article_collections_attributes"=>
[
{"name"=>"abcd", "type"=>"Special", "description"=>"content ","ordering_type"=>""}
]
},
"commit"=>"Save", "id"=>"b8c8ad67-9b98-4705-8b01-8c3f00e55919"}
Run Code Online (Sandbox Code Playgroud)
安慰
Article.find("b8c8ad67-9b98-4705-8b01-8c3f00e55919").article_collections.count
=> 2
Run Code Online (Sandbox Code Playgroud)
问题是,每当我们更新文章时,它都会创建多个article_collections.
假设article_collections是2意思是如果我们正在更新文章它创建多个article_collections = 4,它没有更新相同的article_collections,它是新创建的article_collections.
为什么要创建重复项?
ruby rubygems ruby-on-rails strong-parameters ruby-on-rails-4