我刚开始使用rails,所以我跟随他们网站上的getting started。
但是,我仍然坚持创建方法部分。
所以这是我的实际代码
用户控制器
class UserController < ApplicationController
def new
end
def signin
end
def create
render plain: params[:user].inspect
end
end
用户新视图
<%= form_for :user, html: {role: "form", class: "col-md-6"}, url: user_index_path do |f| %>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<%= f.text_field :name, :placeholder => "Username", :class => "form-control" %>
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></span>
<%= f.text_field :email, :placeholder => "Email", :class => "form-control" %>
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
<%= f.password_field :password, :placeholder => "Password", :class => "form-control" %>
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
<%= f.password_field :passwordbis, :placeholder => "Repeat password", :class => "form-control" %>
</div>
</div>
<p>
<%= f.submit :value => "Sign up", :class => "btn btn-success" %>
</p>
<% end %>
路线
get "welcome/index"
root 'welcome#index'
get '/about' => 'high_voltage/pages#show', id: 'about'
get '/contact' => 'high_voltage/pages#show', id: 'contact'
get '/privacy' => 'high_voltage/pages#show', id: 'privacy'
get '/terms' => 'high_voltage/pages#show', id: 'terms'
resources :user do
post 'signin'
end
我得到的错误:
Missing template user/create, application/create
我不明白为什么仍会抛出错误消息而我在create方法中放置了一个render调用。我很确定这是一个愚蠢的初学者错误,有什么帮助吗?
编辑:问题是,如果我删除了create方法,它会抱怨缺少create操作,所以我假设该方法被称为
答案 0 :(得分:1)
如果你正在使用render plain:'some text with methods and variables'
你应该改为使用:
render inline: code with ruby and such here.
inline允许使用Ruby代码,其中plain:只允许使用纯文本。 (即没有Ruby)
http://guides.rubyonrails.org/layouts_and_rendering.html
参见上述参考资料。