Skip to content

Authenticate #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Authenticate #7

wants to merge 15 commits into from

Conversation

claytonflesher
Copy link

Don't merge. Just here for learning purposes.

@farishkash
Copy link
Contributor

Clayton use some LET

@matugm
Copy link
Contributor

matugm commented Oct 6, 2015

What do you think about this regex for the email? /\A\S+@\S+\.\S+\z/
\S stands for 'not an space'

@runyans7
Copy link

runyans7 commented Oct 6, 2015

On the conversation about using form_for or form_tag. I have messed around a lot with forms trying to learn them and the biggest difference I have found is that the model backed form puts the params into a nested hash that allows for mass assignment.

Here is the form that I used:

# Non model backed
<%= form_tag "/posts" do %>
  <%= label_tag :title %>
  <%= text_field_tag :title %>
  <br/>
  <%= submit_tag "Create Post" %>
<% end %>

# Model backed
<%= form_for @post do |f| %>
  <%= f.label :title %>
  <%= f.text_field :title %>
  <br>
  <%= f.submit 'Create Post' %>
<% end %>

Here are the params for a non-model backed form using form_tag:

=> {"utf8"=>"✓",
 "authenticity_token"=>"nXTXG/o6vRICobR/ho1xkpu9KvHFkqIbuh90zcmHkaM=",
 "title"=>"Test post",
 "commit"=>"Create Post",
 "action"=>"create",
 "controller"=>"posts"}

and here are the params for the model backed form:

=> {"utf8"=>"✓",
 "authenticity_token"=>"nXTXG/o6vRICobR/ho1xkpu9KvHFkqIbuh90zcmHkaM=",
 "post"=>{"title"=>"Test post"},
 "commit"=>"Create Post",
 "action"=>"create",
 "controller"=>"posts"}

It's a subtle but important difference.

@claytonflesher
Copy link
Author

One great use case for form_tags might be when you're building multiple objects with the same form.

For example, I have an app that uses of form_tag to build a User from :email and :password, and a UserProfile with :address and an api call performed using :address.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants