javascript - Empty params - RoR -


i have next view

new.html.erb

<%= form_tag ({controller: "nodes", action: "new"}), :id => "users_search" %>   <%= text_field_tag :search, params[:search], :autocomplete => 'off' %>   <div id='users'>     <%= render 'users' %>   </div> <% end %> <%=form_for @node |f| %>   **<%= f.hidden_field :parent_id %>**   <%= f.hidden_field :user_id, :value => current_user.id  %>   <%= f.hidden_field :ocuped, :value => true %>   <%= f.text_field :custom_node_name %>   <%= f.check_box :terms_of_service,{}, true,false %>   <%= f.submit "pagar", class: "button postfix" %> <% end %> 

the nodes_controller.rb

def new @node = node.new   @parent = node.search(params[:search]).where(:ocuped => true)  if not @users.nil?   if @users.count == 1     @node_incomplete = @users.nodes.where(" sons < ? , ocuped = ?",2,true).first   else     @node_incomplete = @users.first.nodes.where(" sons < ? , ocuped = ?",2,true).first   end   @son_of_incompleted_node = @node_incomplete.children end  respond_to |format|   format.html   format.js { render } end 

end

_users.html.erb

<% if not @parent.nil? %> <% @parent.each |u| %>     <ul class="inline-list">         <li class="img-simple" style = "text-align: center; background-image: url('<%= u.user.profile_img %>')"></li>             <li style="display:table-cell; vertical-align: middle;"><h6><%= u.user.name %></h6><p><%= u.user.email %></p></li>     </ul>     **<% params[:parent_id] = u.id %>** <% end %> 

new.js.erb

$('#users').html('<%= escape_javascript(render("users")) %>'); 

application.js

//= require jquery //= require jquery_ujs //= require turbolinks //= require foundation //= require_tree .  $(function() {   $("#users_search input").keyup(function() {     $.get($("#users_search").attr("action"), $("#users_search").serialize(), null, "script"); return false;   }); }); 

node.js.cofee

jquery ->   # ajax search on keyup   $('#users_search input').keyup( -> $.get($("#users_search").attr("action"), $("#users_search").serialize(), null, 'script') false   ) 

everything works fine except when send second form parameter " parent_id " empty , , creates node value " parent_id = nil " .

image


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -