这可能是非常直接和简单的,但我是非常新的和轨道上的红宝石noob.我有一个简单的电子邮件PHP脚本,我在旧网站上使用,但现在因为我已转换为rails我不知道如何创建等效的那个.
我尝试使用rails generate mailer Notifier然后在里面添加了一个发送和发送电子邮件的欢迎方法.但是在用户控制器中(在创建时,当用户创建帐户时,他们的电子邮件地址被发送了一封欢迎电子邮件)我刚刚收到错误消息,表示Notifier未被声明.
在我的用户控制器中
if @user.save
Notifier.welcome(@user).deliver
end
Run Code Online (Sandbox Code Playgroud)
这没用
我正在尝试使用open-uri获取网址.
我的代码非常简单
url = open("http://localhost:3000/descriptions")
return render :text => url.to_json
当我运行此代码时,我收到超时错误.
当我请求"http:// localhost:3000"时,我得到了我的主页(这是正确的).所以看来这是在某个地方的路径上打破.我已经尝试过使用net-http和uri(不确定这是否会产生影响)我仍然有同样的问题.我想得到一个路径和一个查询,但我似乎无法让它工作.
说我有一个班级:
function Foo() {
this.foo1 = null;
this.foo2 = function() { return false;};
}
Run Code Online (Sandbox Code Playgroud)
我希望其他对象从中继承变量和函数.
function Bar(){}
function Baz(){}
Run Code Online (Sandbox Code Playgroud)
然后实例化我的对象:
var bar = new Bar();
bar.foo1 // returns null
bar.foo2() // returns false
Run Code Online (Sandbox Code Playgroud)
什么是适当的功能包括 Foo在Bar和Baz?
我已经做了Bar.prototype = new Foo();但似乎在我们心爱的IE上失败了(<9).
我目前运行Rails 3.1并使用最新版本的Wicked_pdf进行PDF生成.我已经正确设置了所有内容,并且PDF生成得很好.
但是,我希望用户能够单击按钮以下载pdf.目前,单击时,浏览器将呈现pdf并将其显示在页面上.
<%= link_to "Download PDF", { :action => "show", :format => :pdf }, class: 'button nice red large radius', target: '_blank'%>
Run Code Online (Sandbox Code Playgroud)
我的控制器.
def show
@curric = Curric.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @curric }
format.pdf do
render :pdf => @curric.name + " CV",
:margin => {:top => 20,
:bottom => 20 }
end
end
end
Run Code Online (Sandbox Code Playgroud)
我被指向send_file,但绝对不知道如何在这种情况下使用它.
任何帮助表示赞赏.
我从Webrat迁移到Capybara,现在我遇到了很多错误.例如在webrat中我可以在集成测试中使用它:
response.should be_success
Run Code Online (Sandbox Code Playgroud)
但Capybara表明:
Failure/Error: response.should be_success
NoMethodError:
undefined method `success?' for nil:NilClass
Run Code Online (Sandbox Code Playgroud)
有没有提供这种功能的方法?
UPD:我的规格:
require 'spec_helper'
describe "Admins" do
before(:each) do
@admin = FactoryGirl.create(:admin)
visit '/'
click_link "Login"
fill_in "Email", :with => @admin.email
fill_in "Password", :with => 'qwerty'
click_button "Sign in"
end
describe "Admin panel" do
it "should have correct links" do
click_link "User"
response.should be_success
end
end
end
Run Code Online (Sandbox Code Playgroud) 如何使用google-maps-for-rails将颜色参数传递给google maps api?我想根据一个值设置控制器内每个标记的颜色,所以有些是红色,有些是黄色,有些是绿色.我相信它是Symbol中的图标属性,它看着:
https://developers.google.com/maps/documentation/javascript/reference#MarkerOptions
另外,我想在标记内有一个1-99的数字,是否可能?到目前为止,我有这个.
@json = Device.all.to_gmaps4rails do |device, marker|
end
Run Code Online (Sandbox Code Playgroud)
几天来我一直在努力,任何帮助都会受到赞赏.
我已经注意到Google Maps For Rails宝石,否则它可以完美地工作,当我在模型字段中更改地址时,坐标不会自动更新,即使地址字段已更新并保存.我创建了一个调用geocode的before_save方法.
before_save :update_location_coordinates # in model being mapped
protected
def update_location_coordinates
place = Gmaps4rails.geocode(gmaps4rails_address).first
self.longitude, self.latitude = place[:lng], place[:lat] unless place.empty?
rescue
nil
end
Run Code Online (Sandbox Code Playgroud)
这有效,但我想知道是否有必要,因为它似乎应该是宝石中的自动.我错过了什么吗?
谢谢...
PS地理编码返回一个数组,所以我只是采取了第一个(最佳)猜测
构建Rails应用程序的半静态网页的标准方法是什么?
我来自LAMP背景,传统上我有这样的页面:
about.php
index.php
common/
header.php
footer.php
scripts.php
(etc)
sign-up.php
scripts/
jQuery.js
etc
styles/
main.css
(etc)
Run Code Online (Sandbox Code Playgroud)
在这些文件中,会有一个包含页眉,页脚等的php.
我应该生成一个名为Pages的控制器吗?
有没有办法设置渲染集合时的默认行为.到目前为止我所拥有的是:
<%= render @entries %>
Run Code Online (Sandbox Code Playgroud)
它_entry.html.erb为@entries列表中的每个条目呈现部分.我想打印某种消息,例如:'No Entries Found'.有没有明确写入条目部分的方法吗?
我正在编写一个 Sublime2 插件并且有点挣扎。
代码是:
def run(self, edit):
self.edit = edit
self.view.window().show_input_panel("New Controller and View Path (ex: client_area/index )", "", self.trigger, None, None)
def trigger(self, user_entry):
formatted_entry = user_entry.encode('utf-8')
print formatted_entry.__class__
print formatted_entry
if formatted_entry.slice('/')[0] == '':
#some code
Run Code Online (Sandbox Code Playgroud)
输出是:
<type 'str'>
client_area/index
Traceback (most recent call last):
File "./PluginName.py", line 27, in trigger
AttributeError: 'str' object has no attribute 'slice'
Run Code Online (Sandbox Code Playgroud)
我怎么了'str' object has no attribute 'slice'?(Python 版本为 2.6)
ruby ×3
gmaps4rails ×2
actionmailer ×1
capybara ×1
email ×1
erb ×1
google-maps ×1
javascript ×1
open-uri ×1
pdf ×1
php ×1
python ×1
rspec ×1
sendfile ×1
wicked-pdf ×1