我希望它类似于Twitter处理其推文的URL的方式.
例如,现在我的URL看起来像这样:mydomain.com/feedbacks/1/,feedbacks控制器的名称在哪里.
我希望它看起来像:mydomain.com/username/feedbacks/1/类似于Twitter的:twitter.com/username/status/:id/.
我routes.rb看起来像这样:
resources :users do
resources :feedbacks
end
Run Code Online (Sandbox Code Playgroud)
当我这样的时候,它会给我URL mydomain.com/users/1/feedbacks,但我想要URL中的实际用户名.
我怎么做到的?
谢谢.
编辑1:如果您要为此问题添加另一个答案,请确保它针对已给出的答案解决我的意见/问题.否则它将是多余的.
我正在尝试使用OmniAuth,根据Ryan Bates的说法,我应该通过devise_for在我的routes.rb文件中指定以下范围来覆盖Devise Registration控制器:
devise_for :users, :controllers => {:registrations => 'registrations'}
Run Code Online (Sandbox Code Playgroud)
但是,根据Devise's文档,如果我要自定义path_names,那么mydomain.com/users/sign_up/我可以做mydomain.com/register,而不是做,我必须做这样的事情:
devise_for :users, :path_names => { :sign_up => "register", :sign_in => "login", :sign_out => "logout", :settings => "settings", :newpass => "newpass", :changepass => "changepass" }
Run Code Online (Sandbox Code Playgroud)
我试图像这样链接他们两个:
devise_for :users, :controllers => {:registrations => 'registrations'}, :path_names => { :sign_up => "register", :sign_in => "login", :sign_out => "logout", :settings => "settings", :newpass => "newpass", :changepass => "changepass" }
Run Code Online (Sandbox Code Playgroud)
但这不起作用.为了让我去看我的观点views/registrations/new.html.erb,我得去mydomain.com/users/register.如果我去 …
所以我正在使用Nokogiri解析页面并存储如下值:
contents[link[:href]] = content_page.css("p a")
copy = content_page.xpath('//p/text()[1]').text
Run Code Online (Sandbox Code Playgroud)
然后我my_listing就像这样把它们推到我的阵列上:
my_listing << contents[link[:href]]
my_listing << copy
Run Code Online (Sandbox Code Playgroud)
但是,它的作用是为每个条目创建一个2元素数组.
因此contents[link[:href]]存储在my_listing[0],而
copy存储在my_listing[1].
然而,我想要发生的是,my_listing[0][0] == contents[link[:href]]&& my_listing[0][1] == copy.
我该怎么做呢?
我有一个有25列的表,总共宽约2600px.
现在,我有如下所述的结构 - 但它正在该content区域之外流动,并且每列中的内容未正确对齐.实际上,应该在一行上的内容在每行中出现在2或3上.它通常看起来不整洁.
我怀疑这是因为Twitter Bootstrap是为较小的数据集 - 特别是表格而制作的.
但有没有人对我如何让这张桌子看起来不笨重有任何想法?
<div class="container-fluid">
<div class="content">
<div class="row-fluid">
<div class="span12">
<h2>Home</h2>
<table class="table table-striped table-hover table-condensed">
<thead>
<tr>
<th>Name</th>
<th>Phone</th>
<th>Email</th>
<th>Co. Name</th>
<th>Co. Phone</th>
<th>Co. Size</th>
<th>Co. Type</th>
<th>City</th>
.
.
.
</tr>
</thead>
<tr>
<td>John F Kennedy</td>
<td>87698765</td>
<td>jfk@email.com</td>
<!-- Begin Firm Info Here -->
<td>Acme Inc</td>
<td>(876) 987-6543</td>
.
.
.
</tr>
</table>
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
谢谢!
这就是我想要最终产品的样子:
<div class="side-img top"><%= image_tag product.image_url(:banner_thumb).to_s %></div>
<div class="side-img mid"><%= image_tag product.image_url(:banner_thumb).to_s %></div>
<div class="side-img bottom"><%= image_tag product.image_url(:banner_thumb).to_s %></div>
Run Code Online (Sandbox Code Playgroud)
请注意每个div的第二个类都会发生变化product.
那么如何循环这个集合并动态应用这3个类中的每一个,这样我才能得到上述结果?
当我在我的系统上列出Ruby的所有版本时,我得到了这个:
$ rvm list rubies
rvm rubies
ruby-1.8.7-p370 [ i686 ]
ruby-1.9.2-p0 [ x86_64 ]
ruby-1.9.2-p320 [ x86_64 ]
* ruby-1.9.3-p194 [ x86_64 ]
=> ruby-1.9.3-p392 [ x86_64 ]
ruby-2.0.0-p0 [ x86_64 ]
# => - current
# =* - current && default
# * - default
Run Code Online (Sandbox Code Playgroud)
当我在项目的新终端窗口中列出gemset时,我看到:
$ rvm gemset list
gemsets for ruby-1.9.3-p392 (found in /.rvm/gems/ruby-1.9.3-p392)
(default)
=> myapp
boso
global
Run Code Online (Sandbox Code Playgroud)
所以,我改变了1.9.3我想要使用的版本:
$ rvm use 1.9.3-p194
Using /.rvm/gems/ruby-1.9.3-p194
$ rvm gemset list
gemsets for ruby-1.9.3-p194 (found …Run Code Online (Sandbox Code Playgroud) 所以我想做的是根据角色的重定向做重定向current_user.
这就是我所拥有的:
path = case current_user.roles.where(:name => "vendor")
when :vendor
dashboard_path
when :guest
home_path
else
home_path
end
redirect_to path
Run Code Online (Sandbox Code Playgroud)
我正在使用cancan并且唯一的方法来确定用户的角色,我知道,要么做current_user.has_role? :admin或者current_user.roles.where(:name => role_name).
鉴于这些限制(或告诉我另一种方法来确定用户的角色),我如何让这个案例陈述起作用?
编辑1
假设我正在检查多个角色,而不仅仅是我在这里的2个角色 - 可能是4或5.
编辑2
要清楚,这是我目前的设置.
我正在使用Devise,CanCan和Rolify.Rolify允许用户拥有多个角色,但我的应用程序不具备该用例.用户只有一个角色.他们可以是一个vendor, buyer, guest, superadmin.
如果他们是vendor,他们只能看到dashboard_path属于他们的.他们看不到任何其他vendor storefront人属于他人.他们也不应该看到其他供应商的产品.所以,一旦他们登录,他们root_path应该dashboard_path不是home_path每个其他角色root_path将是什么.
如果他们是guest,他们可以看到除价格以外的所有东西 - 我已经有了这个逻辑.我这样做了:
if user.has_role? :guest
can :read, [Product, Vendor, Banner]
cannot :view_prices, Product
end
Run Code Online (Sandbox Code Playgroud)
然后在我看来,我只是做了这样的事情:
<% if …Run Code Online (Sandbox Code Playgroud) 我有一些包含空白选项的选择菜单。当两者都为空白时(通常在第一页加载时),我想显示一些隐藏的 div。
这就是我所拥有的:
$('.variant_options select').each(function() {
if ($(this).attr('value') === '') {
// some code here to show hidden div
console.log("No options chosen");
}
});
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用。
编辑 1
对于它的价值,我尝试过这样的事情:
if (!$(this).attr('value'))
Run Code Online (Sandbox Code Playgroud)
这似乎有效,但它破坏了其他地方的功能。
所以这就是我未压缩的样子:
function extractDropdownValues(){
var all_selected = true;
$('.variant_options select').each(function() {
if (this.selectedIndex == 0) {
all_selected = false;
}
});
Run Code Online (Sandbox Code Playgroud)
这是压缩版本:
extractDropdownValues(){var e=!0;$(".variant_options select").each(function(){this.selectedIndex==0&&(e=!1)});
Run Code Online (Sandbox Code Playgroud)
我感到困惑的e=!0是等同all_selected = true于this.selectedIndex==0if语句的压缩版本.在压缩版本中,它表示if此索引== 0,然后将其设置为false.
但在压缩版本,它看起来像它正在检查selectedIndex等于0,且&&为all_selected = false(即e=!1).但我不希望那条作为if条件,那应该是if条件满足后的结果.
我读错了吗?
PS压缩版本在生产中不起作用,但未压缩版本在开发中工作.我不确定这两者是否相关,但从表面上看,它们似乎与我不相同.
编辑1
我怀疑,我通过JS预处理器运行缩小的JS,这是结果:
function extractDropdownValues() {
var e = !0;
$(".variant_options select").each(function () {
this.selectedIndex == 0 && (e = !1)
});
Run Code Online (Sandbox Code Playgroud)
洙...啊...... WTF正在这里发生?