Barbared
Barbared

Reputation: 800

Fancybox Forms in Rails don't work properly

I know I'm a newbie in Rails but this is the second day I'm going to waste because of this. Could anybody help me to figure out what I am doing wrong?

I want my user to register from the home page. Click on "Register" button and a fancybox appears with two tabs inside the box, because they can choose between two different forms of registration. Everything is set right, because the fancybox appears but there an error message inside.

In the home page:

<ul class='nav pull-right'>
   <%= render 'devise/menu/registration_items' %>
</ul>

In registration_items:

<% if society_signed_in? %>
  <li>
    <%= link_to('Edit registration', edit_society_registration_path) %>
  </li>
<% else %>
  <li>
    <%= link_to('Register', regist_setup_path)  %>
  </li>
<% end %>

Then in setup:

<div class="fancybox">
  <h2>Sign up</h2>

  <ul class="nav nav-tabs">
    <li class="active"><a data-toggle="tab" href="#society">Society</a></li>
    <li><a data-toggle="tab" href="#collaborator">Collaborator</a></li>
  </ul>

  <div class="tab-content">
    <div class="tab-pane active" id="society">  
      <%= render :partial => 'societies/form' %>  
    </div>
    <div class="tab-pane" id="collaborator">Collaborator
      <%= render :partial => 'collaborators/form' %>
    </div>
  </div>
</div>

The two render :partial just show the forms correctly.
Then Jquery in the application.js after all the //= require blablabla.js

$(document).ready(function() {
  $(".fancybox").fancybox();
});

I tried to set @society = Society.new and @collaborator = Collaborator.new in my application controller but it still doesn't work

EDIT:
What happen is me clicking on the register button, the setup page appears and when I click on each tab, the box appears with:
The requested content cannot be loaded. Please try again later. error message

Upvotes: 1

Views: 1579

Answers (1)

Jesse Wolgamott
Jesse Wolgamott

Reputation: 40277

I don't think this is rails related -- Fancybox, and other javascript plugins like this, attach to a link element, so that when they are clicked, it will load up the content based on the href of the link.

your jquery call should be (in window load)

$(document).ready(function() {
  $("a.fancybox").fancybox();
});

So I think you'd want this:

<%= link_to('Register', "#popup-signup", :class=>"fancybox")  %>

Then the content in the popup:

<div id="#popup-signup">
  <h2>Sign up</h2>
  ..more stuff here

Upvotes: 4

Related Questions