Ruby on rails 我应该如何在rails应用程序中为多个控制器使用单一模型 [控制器代码检查是否正确]
我试过了,但没用 有人能纠正代码吗 类AuthControllerRuby on rails 我应该如何在rails应用程序中为多个控制器使用单一模型 [控制器代码检查是否正确],ruby-on-rails,Ruby On Rails,我试过了,但没用 有人能纠正代码吗 类AuthControllerauth_路径(@author)do | f |%> def show @author = Author.find(params[:id]) end def new end def create @author = Author.find(params[:id]) @auth = @author.comments.create(comment_params) redirect_to @author
end在控制器中,在get
@author=author.find(params[:id])
和视图中定义与此页面名称相同的方法
def show
@author = Author.find(params[:id])
end
def new
end
def create
@author = Author.find(params[:id])
@auth = @author.comments.create(comment_params)
redirect_to @author
end
private
def author_params
params.require(:author).permit(:topic, :content)
end
然后在routes.rb中
render :template => "user/authors/welcome"
这不起作用,我对我的控制器有疑问,所以我把控制器的代码发给你also@TanmayAgrawal-请正确格式化。。如果它是一个新页面,则在控制器
defnew@author=author.newend
和视图:author,:url=>auth_路径(@author)do | f |%>
def show
@author = Author.find(params[:id])
end
def new
end
def create
@author = Author.find(params[:id])
@auth = @author.comments.create(comment_params)
redirect_to @author
end
private
def author_params
params.require(:author).permit(:topic, :content)
end
<%= form_for @author, :as => :author, :url => auth_path(@author) do |f| %>
class User::AuthorsController < ApplicationController
def welcome
end
end
module User
class AuthorsController < ApplicationController
def welcome
end
end
end
render :template => "user/authors/welcome"
namespace :user do
resources :authors
end