Note that there are some explanatory texts on larger screens.

plurals
  1. POMy form does not store the params in model
    primarykey
    data
    text
    <p>I have a rails project in which I have to save subscribers data in the database without refreshing the page!</p> <p>So I coded an Ajax button. when I click the button an alert popups and returns the ID of new user that has just been created. The problem is when I look at rails console for last record of model <em>User.last</em> all fields of the record is nil (except ID). How can I fix this problem?</p> <hr> <p>routes:</p> <pre><code>users_new GET /users/new(.:format) users#new users GET /users/index(.:format) users#index create POST /users/create(.:format) users#create </code></pre> <p>here is my view in app/views/users/new.html.haml</p> <pre><code>.form1 %h1 Subscriber =form_for @user do |form| - unless @user.errors.empty? - @user.errors.full_messages.each do |message| .alert.alert-danger %ul - @user.errors.full_messages.each do |message| %li= message %div{ :data =&gt; { :role =&gt; :content} } .row.form-group .col-lg-3 %label Email: =form.text_field :email, :class =&gt; 'form-control' .row.form-group .col-lg-3 %label Name: =form.text_field :name, :class =&gt; 'form-control' .row.form-group .col-lg-3 %label Phone Number: =form.text_field :phone_number, :class =&gt; 'form-control' .row.form-group .col-lg-3 %label Address: =form.text_field :address, :class =&gt; 'form-control' %ui-grid-a %ui-block-a %a.primary{ :data =&gt; { :role =&gt; :button, :remote =&gt; create_path, :parent =&gt; '.form1', :success =&gt; 'saved' } } Save </code></pre> <p>This is the controller:</p> <pre><code>class UsersController &lt; ApplicationController def index end def new @user = User.new end def create @user = User.new params[:user] @user.save render :json =&gt; @user end end </code></pre> <p>My js file :</p> <pre><code>function saved(user){ alert(user.id); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload