使用设计和单独的控制器(用户)进行身份验证,这是一个单独的"显示"操作
class UsersController < ApplicationController
#before_filter :authenticate_user!
def show
@user = User.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @user }
end
end
end
Run Code Online (Sandbox Code Playgroud)
到目前为止,视图(users/show.html.erb)仅显示所访问配置文件的用户名
<%= @user.username %>
Run Code Online (Sandbox Code Playgroud)
路由还:
resources :users
Run Code Online (Sandbox Code Playgroud)
我希望这些个人资料页面可以公开访问,如果他们得到一个链接/告知地址,但也想要一个链接可供当前登录的用户访问他的个人资料.我的标题中的一个片段:
<li><%= link_to "Profile", @user %></li>
<li><%= link_to "Settings", edit_user_registration_path %></li>
<li><%= link_to "Logout", destroy_user_session_path, method: "delete" %></li>
Run Code Online (Sandbox Code Playgroud)
目前,@ user就是为了阻止路由错误.我不完全确定要链接到什么,尝试了很多组合,但显然我的铁杆新手心灵缺少了我需要做的额外的事情.任何帮助深表感谢!
(Rails 4,ruby 2.0.0)
附注我最后还希望允许指向个人资料页面的链接以以下格式显示id +用户名:#{id} - #{username}(而不仅仅是用户/ 1 - > users/1 -bbvoncrumb).
我想要一个链接来打开一个显示单击对象(word.title)的模态,显示在每个循环中.现在它打开模态,然后再次为循环中的每个项目显示它.
<h1>Glossary of words</h1>
<p>Pagination at 25</p>
<table class="table table-hover">
<thead>
<tr>
<th>Title</th>
<th>Definition</th>
<th>Usage</th>
<th>Word Type</th>
</tr>
</thead>
<tbody>
<% @words.each do |word| %>
<tr>
<th scope="row">
<a href="#" data-toggle="modal" data-target=".bs-example-modal-sm">
<%= word.title %>
</a>
<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<%= word.title %>
</div>
</div>
</div>
</th>
<td><%= word.title %></td>
<td><%= word.definition %></td>
<td><%= word.word_type %></td>
</tr>
<% end %>
</tbody>
</table>
// Word Modal
$('.bs-example-modal-sm').modal()
Run Code Online (Sandbox Code Playgroud) 我在functions.php中启用了缩略图和大小:
add_theme_support( 'post-thumbnails' );
add_image_size( 'post-thumbnail', 150, 150, true );
add_image_size( 'featured-thumbnail', 360, 300, true );
Run Code Online (Sandbox Code Playgroud)
它们在循环中被正确调用,虽然crop设置为true,但我还没有看到任何图像裁剪到指定的大小,它们都"看似"成比例.我每次做出改变都会重新生成缩略图,但没有任何效果.我已经搜索了很多答案,几乎没有修复(我不想使用插件并手动完成).
有任何想法吗?
新手到这里的铁路,所以忍受我.
使用ruby 2.0的Rails 4上的新应用程序,我安装了Devise并按照说明(默认root等).在github上设计自述文件说它应该与rails4兼容但是
我看到像这样的堆栈溢出问题,但很多答案直接进入了一些复杂的谈话.我得到我需要为质量分配指定允许的属性,但是如何?在哪里?哪些属性需要被允许,所有这些属性?只有我希望同时更改/创建的那些?
从错误判断我会创建一个从Devise :: registrationsController继承的registrations_controller.rb吗?我在那里指定了什么?
任何一步一步,新手友好的答案非常感谢.我已经用尽了自己尝试从这里的答案和谷歌搜索的各种网站的不同代码.
我决定使用新的Rspec 3(+ capybara/factory_girl)开始一个新项目,并且在学习新语法时遇到了麻烦.现在我有
user_pages_spec.rb(功能)
scenario "Signing Up" do
let(:submit) { "Sign up" }
scenario "With valid information" do
background do
fill_in "Username", with: "bbvoncrumb"
fill_in "Email", with: "bbvoncrumb@example.com"
fill_in "Password", with: "foobar123"
fill_in "Password confirmation", with: "foobar123"
end
scenario "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
end
end
Run Code Online (Sandbox Code Playgroud)
使用未定义的方法'let'失败.和:
static_pages_spec.rb(控制器)
describe StaticPagesController do
describe "GET 'home'" do
it "returns http success" do
get :home
expect(response).to be_success
end
end
end
Run Code Online (Sandbox Code Playgroud)
使用"未定义的方法'获取'.(这只是默认的控制器规范)