我正在关注Railscast#199,以便在移动浏览器中查看我的网络应用程序.除非我尝试在移动版本中使用UJS访问选项卡式界面中的信息,否则它的效果很好.单击选项卡可在Web应用程序中运行,但在移动端,我收到406错误.(我在Safari中将用户代理设置为iPhone后尝试了这一点.我还在iOS模拟器和我的iPhone上进行了测试.两者都没有加载任何东西.)
下面是其中一个选项卡的一些代码.任何人都可以帮我定位正在发生的事情吗?这是我的代码.
以下是profile_about操作profiles_controller.rb:
def profile_about
@profile = Profile.find(params[:id])
respond_to do |format|
format.js { render :layout => nil }
end
end
Run Code Online (Sandbox Code Playgroud)
在我profiles/show.mobile.erb(这是完全相同的代码profiles/show.html.erb):
<div id="tabs">
<ul id="infoContainer">
<li><%= link_to "Cred", profile_cred_profile_path, :class=> 'active', :remote => true %></li>
<li><%= link_to "About", profile_about_profile_path, :class=> 'inactive', :remote => true %></li>
</ul>
<div id="tabs-1">
<%= render :partial => 'profile_cred' %>
</div>
</div><!-- end tabs -->
Run Code Online (Sandbox Code Playgroud)
(注意:我有一个文件profiles/_profile_about.html.erb和profiles/_profile_about.mobile.erb.)
这是我的profiles/profile_about.js.erb:
$("#tabs-1").html("<%= escape_javascript(render(:partial => 'profile_about'))%>");
Run Code Online (Sandbox Code Playgroud)
我的Heroku日志显示406: …
我有一个表单在我的用户设置中工作,用于显示或隐藏用户个人资料的一部分.表单是a check_box_tag,当单击它时,我使用jQuery提交表单.这一切都运作良好.单击该复选框可将布尔值从中切换为true,false反之亦然.但是,如果我的布尔值是,我希望复选框显示为已选中false.考虑到下面的代码,我该怎么做?
我的控制器update_attribute对配置文件的操作:
def edit_show_hometown_settings
@profile = current_user.profile
if @profile.show_hometown == true
if @profile.update_attributes(:show_hometown => false)
redirect_to settings_path
else
redirect_to settings_path, :notice => 'Oops, something went wrong. Please try again.'
end
elsif @profile.show_hometown == false
if @profile.update_attributes(:show_hometown => true)
redirect_to settings_path
else
redirect_to settings_path, :notice => 'Oops, something went wrong. Please try again.'
end
end
end
Run Code Online (Sandbox Code Playgroud)
我的表格:
<%= form_tag({:action => "edit_show_hometown_settings", :controller => "profiles"}, :html => {:multipart => true }) do …Run Code Online (Sandbox Code Playgroud) 提前为初学者问题道歉,但由于我是初学者,所以:在我的Rails 3应用程序中,我的Profile模型属性为:subject.在我的表单中,我有以下代码供用户分配:subject:
<%= f.select :profile_subject, options_for_select([['Select', 0], ['Arts', 1], ['Biology', 2], ['Business', 3], ['Chemistry', 4], ['English', 5], ['Foreign Language', 6], ['Government', 7], ['Health', 8], ['History', 9], ['Math', 10], ['Physics', 11], ['Vocational', 12]]) %>
Run Code Online (Sandbox Code Playgroud)
我想将:subject字符串用于两件事:
我认为我没有在我的数据库(或构建表单)中正确设置它,因为我似乎只存储id("ex:1")而不是字符串("ex:Arts").在我删除选项ID之前,我很好奇:对于这样的事情,在选择中包含选项ID和字符串是否被认为是一种好习惯?或者删除id并仅将其保存为字符串数组?
询问所有这些的原因是关于我的搜索表单.正如我所提到的,我正在使用Ransack,而我只是不确定如何f.select使用一堆字符串来完成工作.
我找到了一些用于生成我在我的网站上使用的CSS3按钮的代码.在浏览器中查看时按钮看起来很棒.但是,在我的网站的移动网络版本(使用相同的样式)上,按钮的呈现方式不同.更奇怪的是,如果我使用Safari并使用iPhone用户代理查看我的网站,按钮看起来应该是这样.但是在iOS模拟器中他们没有.有人可以帮我理解为什么吗?
这是我正在使用的代码:
.button, #button .button, li.button .button {
display: inline-block;
zoom: 1;
*display: inline;
vertical-align: baseline;
outline: none;
cursor: pointer;
text-align: center;
text-decoration: none;
font: 14px/100% Arial, Helvetica, sans-serif;
padding: .5em 1.5em .55em;
text-shadow: 0 1px 1px rgba(0,0,0,.3);
-webkit-border-radius: .5em;
-moz-border-radius: .5em;
border-radius: .5em;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.2);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.2);
box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.orange, #button .orange {
color: #fef4e9;
border: solid 1px #da7c0c;
background: #f78d1d;
background: -webkit-gradient(linear, left, top, left bottom, from(#faa51a), to(#f47a20)); …Run Code Online (Sandbox Code Playgroud) 我在iOS 7中使用视图控制器时出现问题.我正在尝试找出在导航栏和状态栏下调整视图布局的最佳方法,同时保持导航栏的透明度/模糊.例如,如果我有一个视图控制器:
def viewDidLoad
@scroll = UIScrollView.alloc.initWithFrame(new_frame)
@scroll.bounces = true
@scroll.delegate = self
@scroll.alwaysBounceVertical = true
@scroll.scrollsToTop = true
@scroll.contentSize = CGSizeMake(UIScreen.mainScreen.bounds.size.width, scroll_frame.size.height)
self.view.addSubview(@scroll)
end
Run Code Online (Sandbox Code Playgroud)
我的内容显示在导航栏下,我获得了iOS 7过渡指南.要纠正这个问题,如果我在viewDidLoad中添加以下内容:
self.edgesForExtendedLayout = UIRectEdgeNone
布局已调整,但导航栏不再具有透明度或模糊,因为视图不会在其后面延伸.
如果我不调整scrollView insets而不是设置layout的边缘:
self.automaticallyAdjustsScrollViewInsets = false
然后将我的滚动框更改为:
def viewDidLoad
nav_bar_height = self.navigationController.navigationBar.frame.size.height
status_height = UIApplication.sharedApplication.statusBarFrame.size.height
height = nav_bar_height + status_height
scroll_frame = self.view.bounds
new_frame = CGRect.new([0, height], [scroll_frame.size.width, scroll_frame.size.height])
@scroll = UIScrollView.alloc.initWithFrame(new_frame)
@scroll.bounces = true
@scroll.delegate = self
@scroll.alwaysBounceVertical = true
@scroll.scrollsToTop = true
@scroll.contentSize = CGSizeMake(UIScreen.mainScreen.bounds.size.width, scroll_frame.size.height)
self.view.addSubview(@scroll)
end …Run Code Online (Sandbox Code Playgroud) 我想这是一个重复的问题,但我还没有发现它,所以我想我会问.我有一个User模型Profile通过多态关联不同类型的模型.就像是:
class User < ActiveRecord::Base
belongs_to :profile, polymorphic: true
end
class Profile < ActiveRecord::Base
has_one :user, as: :profile
end
class FacebookProfile < ActiveRecord::Base
has_one :user, as: :profile
end
Run Code Online (Sandbox Code Playgroud)
我想在User上执行一个查询,返回按其个人资料对象的名字排序的用户.在没有任何多态关系之前,我可以通过以joinson 开头:profile,但我知道这不适用于多态.
除了使用sort或sort_by喜欢之外,还有更好的方法吗?
User.all.sort_by {|user| user.profile.first_name }
Run Code Online (Sandbox Code Playgroud) postgresql ruby-on-rails polymorphic-associations active-record-query
在我的应用程序中,我想publish_actions使用Facebook iOS SDK的v4.x 撤销Facebook的许可.(我使用FBSDKCoreKit,FBSDKLoginKit以及FBSDKShareKit作为版本豆荚4.5.1).它的工作有点像我所期望的-它返回的成功,当我使用图形API浏览器让我的权限之后,它表明publish_actions被拒绝.但是,如果我FBSDKAccessToken在执行此操作后检查本地权限,则表示publish_actions没有拒绝.我认为那是因为FBSDKAccessToken缓存了.由于我没有在文档中看到更新它是必需的,我认为我错过了一些东西或者只是做错了什么.所以我想知道是否有人遇到过此问题并且已经解决了问题.
我用来撤销权限的代码如下:
request = FBSDKGraphRequest.alloc.initWithGraphPath("me/permissions/publish_actions",
parameters: {"fields" => ""},
tokenString: FBSDKAccessToken.currentAccessToken.tokenString,
version: nil,
HTTPMethod: "DELETE")
connection = FBSDKGraphRequestConnection.new
connection.addRequest(request, completionHandler: lambda {|connection, result, error|
if !error && result["success"] == true
# Revoking the permission worked
else
# Things went wrong
end
})
connection.start
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法来删除Rails中的表并重新开始并遇到了这样的答案:Rails数据库迁移 - 如何删除表?
但是,当我运行时,drop_table :examples我收到以下错误:
-bash: drop_table: command not found
Run Code Online (Sandbox Code Playgroud)
这是我的create_examples迁移文件:
def self.down
drop_table :examples
end
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助指导我解决这个问题并让我了解我做错了什么吗?我需要修复它,因为此特定迁移阻止执行rake db:migrate,生成以下错误:
== CreateExamples: migrating ====================================================
-- create_table(:examples)
rake aborted!
An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: table "examples" already exists: CREATE TABLE "examples" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "content" varchar(255), "user_id" integer, "created_at" datetime, "updated_at" datetime)
Run Code Online (Sandbox Code Playgroud)
谢谢!(如果我需要提供更多代码,请告诉我.)
我Users和Groups我的Rails 3应用程序之间有一个HABTM关联.我正在学习Rails的书建议运行以下命令行来创建联接迁移:
rails generate migration create_groups_users
Run Code Online (Sandbox Code Playgroud)
但是在文档中看起来我应该运行:
rails generate migration create_groups_users_join_table
Run Code Online (Sandbox Code Playgroud)
因此,以下内容将在我的_create_groups_users.rb迁移中:
class CreateGroupsUsersJoinTable < ActiveRecord::Migration
Run Code Online (Sandbox Code Playgroud)
是否join_table需要添加?
在我的 Rails 3 应用程序中,我希望允许用户指定其他人可以搜索他们个人资料的哪些部分。如果我想让整个用户不可见,我知道如何执行此操作,但是如何设置以便可以将多个字段指定为可搜索或不可单独搜索?
更多信息:
在功能方面,我想根据用户选择在/settings. 例如,配置文件的某些部分将是@user.profile.hometown或@user.profile.current_city。我正在结合Railscasts #52和Trevor Turk 的教程来设置其他人可以通过设置中的复选框搜索的内容。
在设置中定义可搜索性后,当用户搜索(或过滤)/users索引时,未隐藏的内容将是公开的和可搜索的。就隐藏表列或分组而言,这在数据库中是如何工作的,我考虑过隐藏表,但这可能不是最好的解决方案。我是初学者,老实说并没有真正考虑过这个问题。
button ×1
checkbox ×1
css3 ×1
drop-table ×1
facebook ×1
ios7 ×1
layout ×1
mime-types ×1
mobile ×1
postgresql ×1
rake ×1
rubymotion ×1
select ×1