Created
July 12, 2012 06:13
-
-
Save amiel/3096204 to your computer and use it in GitHub Desktop.
A super simple inline object to render a form
This file contains hidden or 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
| class SessionsController < ApplicationController | |
| def new | |
| @user = OpenStruct.new.tap do |model| | |
| def model.class | |
| OpenStruct.new(name: 'User').tap do |klass| | |
| klass.model_name = ActiveModel::Name.new(klass) | |
| end | |
| end | |
| end | |
| end | |
| end |
This file contains hidden or 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
| <%= simple_form_for @user, url: new_user_session_path do |f| %> | |
| <%= f.input :email %> | |
| <%= f.input :password %> | |
| <%= f.button :submit, 'Sign In' %> | |
| <% end %> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If only calling
form_for @userresulted in a call to@user.model_nameinstead of@user.class.model_name.The culprit is
ActiveModel::Naming.model_name_from_record_or_class