Ruby 1.9.3
Gemfile的一部分
#...............
gem "pony"
gem "bcrypt-ruby", :require => "bcrypt"
gem "nokogiri"
#..................
Run Code Online (Sandbox Code Playgroud)
当我尝试安装宝石时,我收到一个错误
alex@ubuntu:~/$ bundle
Fetching gem metadata from http://rubygems.org/.........
Fetching gem metadata from http://rubygems.org/..
Enter your password to install the bundled RubyGems to your system:
#####............................................................
Installing bcrypt-ruby (3.0.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from extconf.rb:36:in `<main>'
Gem files will remain installed in /home/alex/.bundler/tmp/5526/gems/bcrypt-ruby-3.0.1 for inspection.
Results …
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,用户可以创建业务.当他们触发index
我的行动时,我BusinessesController
想检查一个企业是否与以下内容相关current_user.id
:
new
操作.我试图用这个:
if Business.where(:user_id => current_user.id) == nil
# no business found
end
Run Code Online (Sandbox Code Playgroud)
但即使业务不存在,它也总是会回归......
如何测试数据库中是否存在记录?
我有一个大div:
.limeskin:hover {
background: #eee;
cursor: pointer;
display: block;
}
Run Code Online (Sandbox Code Playgroud)
我想要点击.因为我正在使用Rails,所以我需要点击一个Rails链接:例如
<%= link_to 'Edit Your Email Address', edit_user_path %>
Run Code Online (Sandbox Code Playgroud)
我正在努力解决这个问题.
这是整个块:
<% @user.posts.each do |post| %>
<div class="lists">
<ol class="limeposts">
<li>
<div class="limeskin">
<div class="limebox">
<div class="limecost">
<b>Price:</b>
<%= number_to_currency(post.price, :unit => "R") %><br>
[...]
<% end %>
Run Code Online (Sandbox Code Playgroud)
任何简单的法律可行答案?
谢谢
我想允许一些特定的标签,如(<br>
),但让rails继续逃避其他人.Html_safe似乎没有任何参数.最顺畅的方法是什么?
我一直在阅读put和post请求之间的区别,我有一些与rails相关的问题:我想更改已经创建的行中的一个特定字段...我应该使用put还是post请求?例如以下不同?
#Assume this is a put request
def update
@model=Model.find(x)
@model.field="new_field"
@model.save
end
#Assume this is a post request
def update
@model=Model.find(x)
@model.field="new_field"
@model.save
end
#What if I use the rails update method?
def update
@model=Model.find(x)
@model.update(model_params)
@model.save
end
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我在sql中并不强大,而且对rails来说相对较新.该
Case
attr_accessible client_id
belongs_to Client
Client
attr_accessibe name
has_many Cases
Run Code Online (Sandbox Code Playgroud)
我可以通过client_id直接查询并按预期获得记录
Case.where(client_id: 1)
Run Code Online (Sandbox Code Playgroud)
但我想通过client.name查询
Case.where(client.name => "Foo")
Run Code Online (Sandbox Code Playgroud)
这给了我一个错误,告诉我客户端不是一个案例的方法.
Undefined method or local variable
Run Code Online (Sandbox Code Playgroud)
最终,我要做的事情非常简单:获得属于客户端"Foo"的第一个Case.我希望使用的查询就是这个.
Case.where(client.name => "Foo").first
Run Code Online (Sandbox Code Playgroud)
它应该是什么?
有没有办法在link_to中包含重定向?我想在删除后刷新当前页面.但是,您可以从应用程序中的多个视图中删除相同的记录.
这是link_to:
<%= link_to 'Delete', expense, confirm: 'Are you sure?', method: :delete, :class => 'btn btn-mini btn-danger' %>
Run Code Online (Sandbox Code Playgroud)
如果没有,将current_url保存在flash [:fromurl]中然后将其放入Controller destroy部分是这样的:
respond_to do |format|
format.html { redirect_to flash[:fromurl] }
format.json { head :no_content }
end
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助!
我正在使用所选的jQuery插件(由Harvest).它在(document).ready上运行正常,但我有一个按钮,当单击它时,使用ajax动态创建更多选择对象,我想使用"选择"功能.但是,只有原始选择元素具有"选定"功能,而新(动态创建)功能不起作用.我正在使用jQuery.get来追加新元素.以下是代码示例:
jQuery(".select").chosen();//this one loads correctly
jQuery("#add-stage").click(function() {
jQuery.get('/myurl',{},function(response) {
//response contains html with 2 more select elements with 'select' class
jQuery('#stages').append(response);
jQuery(".select").chosen();//this one doesn't seem to do anything :-(
});
});
Run Code Online (Sandbox Code Playgroud)
我在想某个地方需要一个.live()函数,但我还没有想到它.任何帮助深表感谢!
注意 - 我没有尝试动态加载新选项,如使用文档中所指定的那样 trigger("liszt:updated");
我有两个型号:(专辑和产品)
1)内部模型
在album.rb里面:
class Album < ActiveRecord::Base
attr_accessible :name
has_many :products
end
Run Code Online (Sandbox Code Playgroud)
内部product.rb:
class Product < ActiveRecord::Base
attr_accessible :img, :name, :price, :quantity
belongs_to :album
end
Run Code Online (Sandbox Code Playgroud)
2)使用" rails console ",如何设置关联(所以我可以使用"<%= Product.first.album.name%>")?
例如
a = Album.create( :name => "My Album" )
p = Product.create( :name => "Shampoo X" )
# what's next? how can i set the album and the product together?
Run Code Online (Sandbox Code Playgroud) 我正在使用Kaminari的分页.它的工作非常棒.
我现在想要的一件事是,加上#comment_section
Kaminari产生的网址.
例如,我的观点就是这样.通过单击Kaminari生成的链接加载页面时,我希望它转到本节的顶部.
可能吗?
<a name="comment_section">
<span id="comment">
<%= render 'users/comment' %>
</span>
<%= paginate @comments, :window => 4 %>
Run Code Online (Sandbox Code Playgroud)