为什么我点击提交时会说这个错误?有没有什么办法解决这一问题??这些对我来说似乎是正确的......
找不到没有身份证的女孩
我对传递参数的看法
<%=form_for :girls, url: url_for( :controller => :girls, :action => :comment ) do |f| %>
<div class="field">
<%= f.label :body %><br />
<%= f.text_field :body %>
</div>
<%= f.hidden_field :id, :value => @girl.id %>
<div class="actions">
<%= f.submit %>
<% end %>
控制器中的评论动作
def comment
@girl = Girl.find(params[:girls][:id] )
@user_who_commented = current_user
@comment = Comment.build_from( @girl, @user_who_commented.id, params[:girls][:body] )
redirect_to :controller => 'girls', :action => 'show', :id => params[:girls][:id]
flash[:notice] = "comment added!"
end
我的路线
Example::Application.routes.draw do
root :to => "top#index"
devise_for :users, :controllers => { :registrations => "registrations" }
get 'girls', :to => 'girls#index', :as => :user_root
match '/girls/comment' => 'girls#comment', :via => :post
get "girls/show"
resources :girls
resources :home
devise_for :users do get 'logout' => 'devise/sessions#destroy' end
resources :girls do
collection do
get 'tag'
end
end
end