Last active
December 15, 2015 22:29
-
-
Save kdavh/5332969 to your computer and use it in GitHub Desktop.
problem with hardcoded html form used with rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### CODE IN models/users/show.html.erb ###### | |
<%= form_for user do |f| %> | |
<%= f.label :name %> | |
<%= f.text_field :name %> | |
<% Team.all.each do |team|%> | |
<%= check_box_tag( "user[team_ids][]", team.id, | |
user.team_ids.include?(team.id), | |
id: "user_team_ids_#{team.id}" | |
)%> | |
<%= label_tag "user_team_ids_#{team.id}", team.name %> | |
<% end %> | |
<%= f.submit %> | |
<% end %> | |
<div>html without rails helper-- NOT WORKING</div> | |
<form action="/users/<%= user.id%>" method="post"> | |
<label for="user_name">Name</label> | |
<input id="user_name" name="user[name]" type="text" value="<%=user.name%>"> | |
<input type="hidden" value="<%= user.id%>" name="user[id]"> | |
<% Team.all.each do |team|%> | |
<br/> | |
<input id="team_<%= team.id %>" | |
name="user[team_ids][]" | |
type="checkbox" | |
<%= "checked=''" if user.team_ids.include?(team.id) %> | |
value="<%= team.id%>"> | |
<label for="team_<%= team.id %>"><%= team.name %></label> | |
<% end %> | |
<br/> | |
<input type="submit" name="commit"> | |
</form> | |
##### GENERATED HTML CODE ###### | |
<form accept-charset="UTF-8" action="/users/1" class="edit_user" id="edit_user_1" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="_method" type="hidden" value="put" /><input name="authenticity_token" type="hidden" value="ejdolds7fQkLjEEVRbaFQE1Hcobd/w9Uokvd1wGLGqA=" /></div> | |
<label for="user_name">Name</label> | |
<input id="user_name" name="user[name]" size="30" type="text" value="mamba" /> | |
<input checked="checked" id="user_team_ids_1" name="user[team_ids][]" type="checkbox" value="1" /> | |
<label for="user_team_ids_1">team super dog</label> | |
<input name="commit" type="submit" value="Update User" /> | |
</form> | |
<div>html without rails helper-- NOT WORKING</div> | |
<form action="/users/1" method="post"> | |
<label for="user_name">Name</label> | |
<input id="user_name" name="user[name]" type="text" value="mamba"> | |
<input type="hidden" value="1" name="user[id]"> | |
<br/> | |
<input id="team_1" | |
name="user[team_ids][]" | |
type="checkbox" | |
checked='' | |
value="1"> | |
<label for="team_1">team super dog</label> | |
<br/> | |
<input type="submit" name="commit"> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment