How can I pass an instance variable to a placeholder in form_form in Rails? -


i'm trying pass instance variable placeholder in form_for:

<h2>sign up</h2>  <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) |f| %>   <%= devise_error_messages! %>      <div class="field">       <%= f.label :number %>       <em>(add 1 + area code w/ no spaces; i.e. 15555555555)</em><br/>       <%= f.text_field :phone, :placeholder => @phone_number.phone_number %>     </div>    <div class="field">     <%= f.label :email %><br />     <%= f.email_field :email, autofocus: true %>   </div> 

when 'undefined method `phone_number' nil:nilclass. @phone_number set same controller view

...here corresponding controller

class users::registrationscontroller < devise::registrationscontroller  before_filter :configure_sign_up_params, only: [:create]  before_filter :configure_account_update_params, only: [:update]  #before_filter :update_sanitized_params, if: :devise_controller?    # /resource/sign_up   def new     @phone_number = phonenumber.find_or_create_by(phone_number: params[:phone_number][:phone_number])      redirect_to welcome_index_path    end 

the redirect_to creates new http request, , instance variables @phone_number aren't persisted across requests. instead can render view directly controller action:

def new   @phone_number = phonenumber.find_or_create_by(phone_number: params[:phone_number][:phone_number])   render welcome_index_path end 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -