English 中文(简体)
部分采用新形式
原标题:render nested partial for new form

I m试图从一个员额控制员内部的一个评论控制员中拿出一个部分。

我的评论资源用于我的员额资源。

路线。

  resources :users, :only => [:show, :create, :new]

  resources :posts do
    resources :comments
    resources :memorybooks
  end

  root to:  static_pages#home 

  match  /channel ,    to:  static_pages#channel 
  match  login , to:  static_pages#login 
  match  /posts , to:  posts#new 
  match  /users , to:  users#new 

我——新,html。

   <%= form_for([@post, @comment]) do |f| %>

      <%= f.label :comment %>
      <%= f.text_field :comment %>

      <p>
      <center>
      <%= f.submit "Submit", class: "btn btn-large btn-primary" %>
      </center>
    <% end %>

我的评论控制器方法:

def create
@post = Post.find_by_id(params[:id])
@comment = @post.comments.build(params[:comment])
    if @comment.save
    redirect_to @current_post
else
    render  / 
end
end

在我的证言中,当我使用以下文字时,我就使用了:

<%= render  comments/new  %>

“新部分”形式出现,但当我担任职务时,我发现错误:

No route matches [POST] "/comments"

而且,如果我用以下线显示的话。

<%= render new_post_comment %>

我发现错误:

undefined local variable or method `new_post_comment 

下面是我的航道。

               users POST   /users(.:format)                               users#create
            new_user GET    /users/new(.:format)                           users#new
                user GET    /users/:id(.:format)                           users#show
       post_comments GET    /posts/:post_id/comments(.:format)             comments#index
                     POST   /posts/:post_id/comments(.:format)             comments#create
    new_post_comment GET    /posts/:post_id/comments/new(.:format)         comments#new
   edit_post_comment GET    /posts/:post_id/comments/:id/edit(.:format)    comments#edit
        post_comment GET    /posts/:post_id/comments/:id(.:format)         comments#show
                     PUT    /posts/:post_id/comments/:id(.:format)         comments#update
                     DELETE /posts/:post_id/comments/:id(.:format)         comments#destroy
    post_memorybooks GET    /posts/:post_id/memorybooks(.:format)          memorybooks#index
                     POST   /posts/:post_id/memorybooks(.:format)          memorybooks#create
 new_post_memorybook GET    /posts/:post_id/memorybooks/new(.:format)      memorybooks#new
edit_post_memorybook GET    /posts/:post_id/memorybooks/:id/edit(.:format) memorybooks#edit
     post_memorybook GET    /posts/:post_id/memorybooks/:id(.:format)      memorybooks#show
                     PUT    /posts/:post_id/memorybooks/:id(.:format)      memorybooks#update
                     DELETE /posts/:post_id/memorybooks/:id(.:format)      memorybooks#destroy
               posts GET    /posts(.:format)                               posts#index
                     POST   /posts(.:format)                               posts#create
            new_post GET    /posts/new(.:format)                           posts#new
           edit_post GET    /posts/:id/edit(.:format)                      posts#edit
                post GET    /posts/:id(.:format)                           posts#show
                     PUT    /posts/:id(.:format)                           posts#update
                     DELETE /posts/:id(.:format)                           posts#destroy
                root        /                                              static_pages#home
             channel        /channel(.:format)                             static_pages#channel
               login        /login(.:format)                               static_pages#login
                            /posts(.:format)                               posts#new
                            /users(.:format)                               users#new

感谢任何帮助! 谢谢!

问题回答

审判

<%= render new_post_comment(@post, @comment) %>

我希望这能够帮助你们。





相关问题
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 ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

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?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

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

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 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签