English 中文(简体)
主计长展览会
原标题:Controller Show Action

我有2个模型用户(devise gem)和简介。

  class User < ActiveRecord::Base
    has_one :profile

  class Profile < AciveRecord::Base
    belongs_to :user

每一种模式的看法都值得一提,但我想在申请内容上有一个联系。

  <% if user_signed_in? %>
  <li><%= link_to current_user.username , profile_path(@profile) %></li>

但这表明我这一错误:

 ActionController::RoutingError (No route matches {:action=>"show", :controller=>"profiles"})

我的履历

  def show 
  @profile = Profile.find(params[:id])

respond_to do |format|
  format.html # show.html.erb
  format.json { r结束er json: @profile }
结束

结束

我的航道:

            profiles GET    /profiles(.:format)                             profiles#index
                     POST   /profiles(.:format)                             profiles#create
         new_profile GET    /profiles/new(.:format)                         profiles#new
        edit_profile GET    /profiles/:id/edit(.:format)                    profiles#edit
             profile GET    /profiles/:id(.:format)                         profiles#show
                     PUT    /profiles/:id(.:format)                         profiles#update
                     DELETE /profiles/:id(.:format)                         profiles#destroy
    new_user_session GET    /users/sign_in(.:format)                        devise/sessions#new
        user_session POST   /users/sign_in(.:format)                        devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format)                       devise/sessions#destroy
       user_password POST   /users/password(.:format)                       devise/passwords#create
   new_user_password GET    /users/password/new(.:format)                   devise/passwords#new
  edit_user_password GET    /users/password/edit(.:format)                  devise/passwords#edit
                     PUT    /users/password(.:format)                                            devise/passwords#update

 cancel_user_registration GET    /users/cancel(.:format)                    registrations#cancel
        user_registration POST   /users(.:format)                           registrations#create
    new_user_registration GET    /users/sign_up(.:format)                   registrations#new
   edit_user_registration GET    /users/edit(.:format)                      registrations#edit
                          PUT    /users(.:format)                           registrations#update
                          DELETE /users(.:format)                           registrations#destroy

我希望这一链接能够显示目前的用户名称(我已经绘制了用户名称),并与当前用户的简介页面链接。

感谢!

最佳回答

它希望你不要在实际使用布局的行动中设置@profile<>/code>,这样它就会变成零,路由人需要假造。

您在任何使申请得以确定的行动中,都需要打上“形象”。 这可能是全球之前的工作。

问题回答

暂无回答




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...