ruby on rails - Render simple_form from partial view on application.html.erb -


i want create partial view registration form , add application layout file because shown in navigation bar in dropdown menu.

how can create form in partial view using simple_form gem , render on application.html.erb?

<%= simple_form_for(@user, url: account_register_path) |f| %> 

considering code above way create form , don't know should define @user used in application layout nor if need it.

can please clarify this?

don't put in partial, have registration view on own, called render...

#app/views/layouts/application.html.erb <%= render "accounts/new" %>  #app/views/accounts/new.html.erb <%= simple_form_for :user, url: account_register_path |f| %> ... 

whilst you can use symbol populate form_for, won't include attributes of model, or various hidden methods give context (such id etc).


if wanted populate accounts#new view/action variable, you'll have set in applicationcontroller:

#app/controllers/application_controller.rb class applicationcontroller < actioncontroller::base    before_action :set_user     private     def set_user       @user = user.new    end end 

this allow use:

#app/views/accounts/new.html.erb <%= simple_form_for @user, url: account_register_path |f| %> 

--

the best way implement ajax -- way, @user object created when need (resolves bloat).

we've done before:

enter image description here

you'd need following:

#app/views/layouts/application.html.erb <%= link_to "new user", account_register_path, remote: true %>  #app/controllers/accounts_controller.rb class accountscontroller < applicationcontroller    respond_to :js, :html     def new       @user = user.new       respond_with @user    end  end  #app/views/accounts/new.js.erb $("<%=j render 'accounts/new' %>").appendto("body"); 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -