我试图在此文本字段中使用值执行if和else语句:
<%= f.text_field :rating, :size => 1, :min => 1, :max => 6, :value => if vind.ratings == 0 else vind.rating_score/vind.ratings, :type => 'range', :step => '1', :id => "#{vind.id}" %>
Run Code Online (Sandbox Code Playgroud)
我在视图中收到此错误:
SyntaxError in Kategoris#show
Showing C:/Rails/konkurranceportalen/app/views/kategoris/_rating.html.erb where line #3 raised:
C:/Rails/konkurranceportalen/app/views/kategoris/_rating.html.erb:3: syntax error, unexpected keyword_else, expecting keyword_then or ';' or '\n'
...ue => if vind.ratings == 0 else vind.rating_score/vind.ratin...
... ^
C:/Rails/konkurranceportalen/app/views/kategoris/_rating.html.erb:3: syntax error, unexpected ',', expecting ')'
...vind.rating_score/vind.ratings, :type => 'range', :step => '...
... ^
Run Code Online (Sandbox Code Playgroud) 如何运行任务reklamer:在cron.rake中每15分钟运行一次?
I have my cron.rake file:
desc "This task is called by the Heroku cron add-on"
task :cron => :environment do
if Time.now.hour % 4 == 0 # run every four hours
puts "Updating feed..."
NewsFeed.update
puts "done."
end
Run Code Online (Sandbox Code Playgroud) 我推迟的工作不起作用.我正在尝试使用应该每15分钟运行一次的延迟作业为rake文件创建后台任务.我已经在rake文件中复制了我的rake任务,并将它们作为方法设置在我的控制器中.我需要延迟工作,因为heroku每1小时只生一个cron.
这是我的应用程序控制器:
class ApplicationController < ActionController::Base
require 'delayed_job'
require 'Mechanize'
require 'pp'
protect_from_forgery
def iqmedier
agent = WWW::Mechanize.new
agent.get("http://www.iqmedier.dk")
form = agent.page.forms.first
form.submit
agent.page.link_with(:href => "/Publisher/Stats").click
form = agent.page.forms.first
form.submit
@stats = agent.page.search('//tr')[-2]
@existing = Reklamer.find(:first, :conditions => {:dato => @stats[0]})
if @existing.nil?
Reklamer.create!(:virksomhed => 'Iqmedier', :dato => @stats[0], :unik_klik => @stats[1], :klik => @stats[2], :unik_vis => @stats[3], :vis => @stats[4], :leads => @stats[5], :ordre => @stats[6], :cpc => @stats[7], :earn => @stats[8])
elsif @existing.dato != Date.today
Reklamer.create!(:virksomhed => 'Iqmedier', …Run Code Online (Sandbox Code Playgroud) 我想操纵一个URL来获取基本站点名称.
例如,我有URL:
http://stackoverflow.com/questions/ask,
Run Code Online (Sandbox Code Playgroud)
哪个应该回来stackoverflow.
如果我有URL:
http://stackoverflow.com/questions/4988199/rails-3-mechanize-socketerror-getaddrinfo-host-or-name-not-known
Run Code Online (Sandbox Code Playgroud)
它也应该只是stackoverflow.
最后一个例子,如果我有URL:
http://www.google.dk/search?q=ruby+string+manipulation
Run Code Online (Sandbox Code Playgroud)
它应该是google.
除了URL的域名之外,我该如何删除所有内容?
我的销毁链接不起作用.
我的索引视图:
<div id="konkurrancer"><%= render 'konkurrencer', :remote => true %></div><%= debug(params) %>
Run Code Online (Sandbox Code Playgroud)
我的发生部分:
<% for konkurrancer in @konkurrancers %> <%= link_to 'Destroy', [:admin, konkurrancer], :method => :delete %> <% end %>
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
No route matches {:action=>"show", :controller=>"admin/konkurrancers", :id=>#<Konkurrancer id: 41, name: " Vind 16.000 kr., til Bilka, Føtex eller Netto
Run Code Online (Sandbox Code Playgroud)
编辑错误查看:
ActionController::RoutingError in Admin/konkurrancers#index
Showing C:/Rails/konkurranceportalen/app/views/admin/konkurrancers/_konkurrencer.html.erb where line #59 raised:
No route matches {:action=>"show", :controller=>"admin/konkurrancers", :id=>#<Konkurrancer id: 41, name: " Vind 16.000 kr., til Bilka, Føtex eller Netto", banner1: "http://partner.smartresponse-media.com/42/1092/1210...", …Run Code Online (Sandbox Code Playgroud) 我有一个网页,我想每次启动我的电脑时打开.该网页受密码保护.
如何创建桌面启动应用程序,每次打开电脑时都会运行该应用程序.那个登录到网页并进入全屏模式?
我正在运行Windows 7.我现在可以创建一个登录网页并进入全屏模式的程序.我可以简单地把它放在起始地图中.
但是我该如何创建桌面程序呢?
我是Windows编程的新手,但我知道编程轨道.
我以前没有创建任何Windows程序.
我希望得到一些提示,哪种语言最容易创建这个小程序.
我正在尝试为div添加不透明度。
这是我的Jquery:
$('.redDiv').fadeIn(0, 0.5);
Run Code Online (Sandbox Code Playgroud)
我的HTML:
<div class="redDiv" style="background:red;width:20px;height:20px;"> </div>
<div class="divBlue;" style="background:blue;width:20px;height:20px;"> </div>
<div class="divBlack;" style="background:black;width:20px;height:20px;"> </div>
Run Code Online (Sandbox Code Playgroud) 我想在保存或更新之前在我的列上创建gsub.
这是我的控制器:
def dansk(text)
self.text.gsub('å', 'å')
self.text.gsub('Å', 'Å')
self.text.gsub('æ', 'æ')
self.text.gsub('Æ', 'Æ')
self.text.gsub('ø', 'ø')
self.text.gsub('Ø', 'Ø')
end
def update
@photographer = Photographer.find(params[:id])
@photographer.update_attributes(params[:photographer])
@photographer.text = dansk(params[:photographer][:text])
@photographer.text = dansk(params[:photographer][:name])
!@photographer.save
flash[:notice] = " "
render_action 'edit'
end
Run Code Online (Sandbox Code Playgroud)
我做错了什么,为什么文字和名字不是"gsubbed"?
更新: 我的帮手:
def convert_html_entities(text)
text.gsub(/å/,"å")
text.gsub(/æ/,"æ")
text.gsub(/ø/,"ø")
text.gsub(/©/,"©")
text = text.gsub(/["]/, '"')
end
Run Code Online (Sandbox Code Playgroud)