Re-render partial inside a modal

11 views
Skip to first unread message

Dinna Gonzales

unread,
Jun 7, 2014, 8:33:24 PM6/7/14
to rubyonra...@googlegroups.com
Inside my home.html.erb. I am rendering a partial inside a modal for my sign-up.


<div id="myModal" class="reveal-modal" data-reveal>
  <%= render partial: 'users/form', :controller=>"users", :action =>"new" %>
  <a class="close-reveal-modal">&#215;</a>
</div>


In my Users.controller.rb, I am rendering new sign up page if user inputs incorrect information! 

def create
@user = User.new(user_params)
if @user.save
# session[:remember_token] = @user.id
# @current_user = @user
# session[:remember_token] = @user.id.to_s
flash.now[:success] = "You have succesfully signed up!"
redirect_to users_path
else
               render 'new'
end
end


What I actually want to accomplish is rerendering the partial inside the modal once User.save does not work. Please help!!!! :(

Frederick Cheung

unread,
Jun 8, 2014, 7:30:09 AM6/8/14
to rubyonra...@googlegroups.com
On Sunday, June 8, 2014 1:33:24 AM UTC+1, Dinna Gonzales wrote:
> Inside my home.html.erb. I am rendering a partial inside a modal for my sign-up.
>
>
>

>
>

> What I actually want to accomplish is rerendering the partial inside the modal once User.save does not work. Please help!!!! :(

For a response to update only a portion of the page instead of the whole page it has to be an ajax post. Rails does have some builtin support for ajax form submission ( http://guides.rubyonrails.org/working_with_javascript_in_rails.html#form-for). You'll have to write some javascript to handle the success/failure cases yourself (in particular the redirect in the success case will no longer do what you want - you have to do the redirect client side)

Fred

Reply all
Reply to author
Forward
0 new messages