是否可以在Rails中循环对象的属性?我有一个对象而不是编码视图中的每个属性,我想在视图中输出每个属性,因为有很多.
我有一个名为的对象@work_profile
,它有许多属性,主要是布尔复选框值.
编辑:我看到我可以使用@work_profile.attributes
.任何帮助将哈希格式化为更加用户友好的东西都会很棒.
Devise背后的团队通过blogpost http://blog.plataformatec.com.br/2013/05/devise-and-rails-4/宣布
它发布了一个与Rails 4兼容的版本,称之为'3.0 rc' .在同一篇博文中,它也表示正在发布Devise 2.2.4.
我正在尝试构建一个Rails 4应用程序.当我这样做时gem install Devise
,它安装了2.2.4,而不是与Rails 4兼容的版本.
Fetching: devise-2.2.4.gem (100%)
Run Code Online (Sandbox Code Playgroud)
我从blogpost中关于强参数的评论中假设我不能与Rails 4兼容.
我查看了Devise的github页面,但对我来说,如何安装与Rails 4兼容的版本并不明显.你能帮忙吗?
https://github.com/plataformatec/devise
注意,我试过了
gem install devise --version 3.0.0.rc1
Run Code Online (Sandbox Code Playgroud)
但它说
ERROR: Could not find a valid gem 'devise' (= 3.0.0.rc1) in any repository
ERROR: Possible alternatives: devise
Run Code Online (Sandbox Code Playgroud) 我已经使用Ruby一段时间了,我发现,对于更大的项目,它可能会占用相当多的内存.有哪些减少Ruby内存使用的最佳实践?
我正在运行Rails 4.
我有一个名为的模型Challenge
,在我的数据库中我存储了status
用0-4来每个挑战.
但是0-4不是非常语义所以我想定义一些变量(我假设一个常量),这样在任何控制器或视图中我都可以通过调用常量来访问该数字:
# Challenge.rb
class Challenge < ActiveRecord::Base
SUGGESTED = 0
APPROVED = 1
OPEN = 2
VOTING = 3
CLOSED = 4
end
Run Code Online (Sandbox Code Playgroud)
我想在我的视图中访问这些:
# challenge/_details.html.erb
<% if @challenge.status == CLOSED %>
Challenge is closed, broheim!
<% end %>
Run Code Online (Sandbox Code Playgroud)
但我的观点不想呈现.
uninitialized constant ActionView::CompiledTemplates::CLOSED
Run Code Online (Sandbox Code Playgroud)
设置状态变量的最佳方法是什么,以便可以在我需要的任何地方访问它们?(即,@challenge
变量存在的任何地方)
我创建了一个Web服务:
服务将自定义Java对象(DataBean)返回给客户端,但我偶然发现了客户端代码中的异常:
org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement {schemaTargetNs}message
Run Code Online (Sandbox Code Playgroud)
从我所研究的内容开始,我一再重复......我认为这是一个非常普遍的问题,但尚未就如何纠正它做出决定性的答案.
此论坛和其他论坛上的一些帖子声明需要修改WSDL(某些名称空间),或者客户端存根需要修改.有些人甚至声称亚行有一个错误.它肯定是早期版本的Axis中的一个错误,但邮件档案中有很多帖子说明错误是修复的.这些邮件存档与早期版本的Axis2有关.
现在我的问题是:
值得一提的是,我创建了一个类似的Web服务,它将"String"返回给客户端.它工作正常!因此,当涉及复杂数据类型时,它会失败.
Apache的网站上有一些信息,标题为" 已知限制 "......
它写道:" ADB意味着'简单'的数据绑定框架,并不意味着编译所有类型的模式.以下限制是最突出的.
那是问题吗?
以下是WSDL文件的片段,您可能对此感兴趣......
<wsdl:types>
<xs:schema xmlns:ax26="http://mywebservice/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="schemaTargetNs">
<xs:import namespace="http://mywebservice/xsd"/>
<xs:element name="getMsg">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="reqData" nillable="true" type="ax25:DataBean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getMsgResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="ax25:DataBean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://mywebservice/xsd">
<xs:complexType name="DataBean">
<xs:sequence>
<xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" …
Run Code Online (Sandbox Code Playgroud) 我希望这不是一个重复的问题; 我在SO上尝试了其他解决方案,没有任何效果
将我的应用程序推送到Heroku时,推送失败,因为application.css无法编译.
我的终端输出:
Running: rake assets:precompile
rake aborted!
Sass::SyntaxError: Invalid CSS after " */": expected selector, was "@font-face"
(in /tmp/build_17e92975-ae8d-446f-8678-110eeeccfb64/app/assets/stylesheets/adminsite/application.css)
(sass):1845
Run Code Online (Sandbox Code Playgroud)
尝试解决方案
我已经搜索并删除了在../stylesheets/adminsite/目录中@ font-face之前的每个"*/"实例.相同的问题和结果.
我试过设置:
config.assets.compile = true
Run Code Online (Sandbox Code Playgroud)
......同样的问题
编辑
这是我的application.css(不是应用程序级别1,而是adminsite目录中失败的那个)
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. …
Run Code Online (Sandbox Code Playgroud) 在我正在开发的Ruby on Rails 4应用程序中,我需要创建一个页面,将其拉入foo.bar.com
服务器上托管的iframe ,因此我有这个控制器方法:
def iframed_page
response.headers["X-FRAME-OPTIONS"] = "ALLOW-FROM http://foo.bar.com"
end
Run Code Online (Sandbox Code Playgroud)
..现在事实证明,客户也希望我也白名单http://foo.dev.bar.com
.
我知道,对于设置X-FRAME-OPTIONS,"ALLOW-FROM"选项不允许多个子域.但由于这是具有不同子域的相同根域,它会更灵活吗?例如,我可以做类似的事情
response.headers["X-FRAME-OPTIONS"] = "ALLOW-FROM http://*.bar.com"
Run Code Online (Sandbox Code Playgroud)
还有?
iframe ruby-on-rails http-headers x-frame-options ruby-on-rails-4
我已经安装了rspec-rails gem.当我跑步时,rails g model movie showtime_date:date showtime_time:time
我想,我应该得到
invoke active_record
create db/migrate/20130604010556_create_movies.rb
create app/models/movie.rb
invoke rspec
create spec/models/movie_spec.rb
Run Code Online (Sandbox Code Playgroud)
但是当我跑步时rails g model movie showtime_date:date showtime_time:time
我得到了
invoke active_record
create db/migrate/xxxxxxxxxxx_create_movies.rb
create app/models/movie.rb
invoke test_unit
create test/models/movie_test.rb
create test/fixtures/movies.yml
Run Code Online (Sandbox Code Playgroud)
我的gem包有问题吗?我正在使用Rails4 beta.这个版本有错误还是其他什么?
我的应用程序的BDD是这样的 app/features/show_descripitons.feature
Feature: Showtime Descriptions
As a movie goer
I want to see accurate and concise showtimes
So that I can find movies that fit my schedule
@wip
Scenario: Show minutes for times ending with 00
Given a movie …
Run Code Online (Sandbox Code Playgroud) 嗨我正面临这个错误,对rails来说是全新的,所以无法弄清楚是什么导致它
我的newBook.html.erb
<html>
<head>
<title> new Book </title>
</head>
<body>
<h1><%= @hello_message %></h1>
<h1>Add new book</h1>
<%= form_tag :action => 'create' %>
<p>
<label for="book_title">Title</label>:
<%= text_field 'book', 'title' %>
</p>
<p>
<label for="book_price">Price</label>:
<%= text_field 'book', 'price' %>
</p>
<p>
<label for="book_subject">Subject</label>:
<%= collection_select(:book,:subject_id,@subjects,:id,:name) %>
</p>
<p>
<label for="book_description">Description</label>
<br/>
<%= text_area 'book', 'description' %>
</p>
<%= submit_tag "Create" %>
<%= end_form_tag %>
<%= link_to 'Back', {:action => 'list'} %>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我的书模型:book.rb
class Book < ActiveRecord::Base
attr_accessible :title, …
Run Code Online (Sandbox Code Playgroud) 我试图让所有与医生相关联的客户都没有开始他们的第一次会议(一个客户有_许多医生并且可以与他们每个人进行第一次会议)。
到目前为止,我有:
@clients = Client.joins(:doctors).where('doctors.first_session IS NULL').order('clients.id DESC')
Run Code Online (Sandbox Code Playgroud)
但是当客户有例如 2 个医生时,这不起作用。第一个doctor.first_session = null 但第二个不是。这种情况将返回客户端,它不希望它返回。
有任何想法吗?
ruby ×2
activerecord ×1
axis2 ×1
bundler ×1
coding-style ×1
compilation ×1
constants ×1
css ×1
cucumber ×1
devise ×1
exception ×1
heroku ×1
http-headers ×1
iframe ×1
memory ×1
precompile ×1
rspec ×1
rspec-rails ×1
web-services ×1