请原谅我的noob问题。
我有一个设计用户模型,我想在用户sign_in / signs_up之后将其他数据保存到用户模型。
的routes.rb
devise_for :users,
path: '',
path_names: {sign_in: 'login', sign_out: 'logout',sign_up: 'signup'},
controllers: { registrations: 'registrations
devise_scope :user do
match 'users/customer' => 'registrations#customer', :via => [:get], :as => 'customer'
match 'users/theme-selector' => 'registrations#theme_selector', :via => [:get], :as => 'theme-selector'
end
registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
protect_from_forgery :except => :create
def customer
@user = current_user
if @user
render :customer
# render :customer
# redirect_to controller: 'registations', action: 'theme_selector'
else
render file: 'public/404', status: 404, formats: [:html]
end
end
def theme_selector
@user = current_user
if @user
render :theme_selector
else
render file: 'public/404', status: 404, formats: [:html]
end
end
end
end
customer.html.erb
<div class="container huge-top small-bottom"">
<div class="row large-top">
<div class="col-md-8">
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<div class="form-group">
<%= f.label :"Contact Person" %>
<%= f.text_field :contact, class:"form-control" %>
</div>
<div class="form-group">
<%= f.label :"Business Name" %>
<%= f.text_field :name, class:"form-control" %>
</div>
<div class="form-group">
<%= f.label :phone %>
<%= f.text_field :phone, class:"form-control" %>
</div>
<div class="form-group">
<%= f.label :email %>
<%= f.text_field :email, class:"form-control", required: true %>
</div>
<div class="form-group">
<%= f.label :"Mailing Address" %>
<%= f.text_field :address, class:"form-control" %>
</div>
<div class="form-group">
<%= f.label :"Do you currently have a domain?" %>
<%= f.text_area :domain, class:"form-control" %>
</div>
<div class="col-md-5">
<!--%= f.submit '+', :name => "add_additional_fields" %-->
<span><%= f.submit 'Save', class: "btn btn-success" %></span>
<span><!--%= link_to 'Back', customers_path, class: "btn btn-danger" %--></span>
</div>
</div>
</div>
<% end %>
步骤如下:
1.A用户sign_up或sign_in。
2.然后,用户选择呈现customer.html.erb
的客户按钮3.提交客户表单后,必须重定向到theme_selector页面以选择某个主题。
我可以通过在 customer.html.erb 表单中提交数据来更新用户模型。现在我想重定向到theme_selector页面,然后将theme_id传递给用户模型。如果我在客户操作中使用 redirect_to controller:&#39;注册&#39;,操作:&#39; theme_selector&#39; ,它正在跳过客户表单并呈现theme_selector页面。如何制作它在客户表单后重定向到theme_selector。
theme_selector.html.erb
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<div class="row">
<div class="col-md-4 col-sm-4 top-space">
<!-- thumbnail-->
<div class="thumbnail image-height">
<a href="http://theme1./" target="_blank">
<div class="hovereffect">
<img src="/assets/1.jpg" class="img-responsive theme" alt="">
<div class="price-sale"><img src="/assets/new.png"></div>
</div>
<div class="caption">
<h4>Click Here</h4>
<!--p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facere, soluta, eligendi doloribus sunt minus amet sit debitis repellat. Consectetur, culpa itaque odio similique suscipit</p-->
<p><button class="btn-update" role="button">View</button></p>
</div>
</a>
</div>
<div><%= f.radio_button :theme_id, 'theme-1' %> </div>
<!-- thumbnail end -->
</div>
<div class="col-md-4 col-sm-4 top-space">
<!-- thumbnail-->
<div class="thumbnail image-height">
<a href="http://theme2/" target="_blank">
<div class="hovereffect">
<img src="/assets/2.jpg" class="img-responsive theme" alt="">
<div class="price-sale"><img src="/assets/new.png"></div>
</div>
<div class="caption">
<h4>Click Here</h4>
<!--p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facere, soluta, eligendi doloribus sunt minus amet sit debitis repellat. Consectetur, culpa itaque odio similique suscipit</p-->
<p><button class="btn-update" role="button">View</button></p>
</div>
</a>
</div>
<div><%= f.radio_button :theme_id, 'theme-1' %> </div>
<!-- thumbnail end -->
</div>
<div class="row">
<div class="col-md-12 top-space"><%= f.submit 'Submit', class: "btn-addmore" %></div>
</div>
<% end %>
任何帮助或建议都得到高度赞赏。在此先感谢。
答案 0 :(得分:0)
在config/routes.rb
devise_for :users,
path: '',
path_names: {sign_in: 'login', sign_out: 'logout',sign_up: 'signup'},
controllers: { registrations: 'registrations}
devise_scope :user do
get 'users/theme-selector' => 'registrations#theme_selector', :as => 'theme-selector'
在registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
'users/theme-selector'
end
end