开发者

Work after user creation

开发者 https://www.devze.com 2023-02-02 20:56 出处:网络
I create a new user with basic fields as user name and password. Then I redirect to another page where the user is allowed to complete his profile. The page looks like this.

I create a new user with basic fields as user name and password. Then I redirect to another page where the user is allowed to complete his profile. The page looks like this.

Ok, I created the user first. Then I r开发者_运维技巧edirected the user to complete his profile. The profile page looks like this

<h1>User successfully created</h1>
<h3>Would you like to complete your profile now?</h3>
<%= render @profile %>
<%= render @address %>

<%= button_to 'Save',{
            :controller => "users",
                            :action => "update", 
            :id => @user.id,
                            :profile => @profile,               
                            :address => @address                    
                         }, :method => :put %>

The code above executes the update action in the controller. However, I am getting nil for the @profile and @address objects. I guess the button_to is having no effect on the profile and address partials.

The address partial looks as follows

<%= form_for(@address) do |f| %>
  <% if @address.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@address.errors.count, "error") %> prohibited this address from being saved:</h2>

      <ul>
      <% @address.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

    <fieldset>

        <legend>Addresss</legend>

      <div class="field">
        <%= f.label :street_address %>
        <%= f.text_field :street_address, :size => 40 %>
      </div>
      <div class="field">
        <%= f.label :street_address_2 %>
        <%= f.text_field :street_address_2, :size => 40 %>
      </div>
      <div class="field">
        <%= f.label :city %>
        <%= f.text_field :city, :size => 40 %>
      </div>
      <div class="field">
        <%= f.label :state %>
        <%= f.text_field :state, :size => 40 %>
      </div>
      <div class="field">
        <%= f.label :zip_code %>
        <%= f.text_field :zip_code, :size => 40 %>
      </div>

<% end %>

I would appreciate if anyone would be able to help me on this.


The button_to method only creates a button which an be used to call an controller/ go to another page.

If you want to allow the user to modify fields, you need to use a form. Please read this guide on forms for more information, especially part 2 is of interest for your situation I guess.

Edit: You need a submit button in your form to submit it, not a button_to outside the form. If you want to have both partials submitted at the same time, you need 1 big form and a controller which is able to process the data of both models.

0

精彩评论

暂无评论...
验证码 换一张
取 消