Problem in using thickbox3.1 with rails..! - ruby-on-rails

I am using rails to build my application and I want a thickbox on clicking a particular link..
I use the below code in my partial which is displayed in a division of a page and on clicking the user.name, i need the thickbox.. when i use the below code, nothing happens..
<%= link_to_function user.name,remote_function(:update=>"result", :url => {:action => :resultsuser}, :with => "'id='+#{user.id}+'&height=400&width=600'") %>
i have included the
<%= javascript_include_tag 'jquery' %>
<%= javascript_include_tag 'thickbox' %>
jQuery.noConflict()
<%= stylesheet_link_tag("thickbox") %>
and also replaced all $ by jQuery in the thickbox.js file.. nothing happens..
please help me out.

Did you put the
jQuery.noConflict();
into a scripttag?

Try adding the class option in the link_to_function helper method.
<%= link_to_function user.name,remote_function(:update=>"result", :url => {:action => :resultsuser}, :with => "'id='+#{user.id}+'&height=400&width=600'", :class => "thickbox") %>

Related

Rails 3: form_for missing closing </form> tag

I am using a form_for in one of my views in my rails app, but for some reason the closing tag is not being generated, and this will be handled safely in most browsers, except IE 8 and lower.
Here's some sample code:
<%= form_for object, :remote => true, :url => remote_update_path, :html => {:name => "form_#{id_number}", :id => "form_#{id_number}"} do |f| %>
<%= hidden_field_tag "field_a", object[:field_a] %>
<ul class="class1">
<li> <%= f.check_box :field_b, :class => "class2", :id => "b" %> B</li>
<li> <%= f.check_box :field_c, :class => "class2", :id => "c" %> C</li>
</ul>
<% end %>
For some reason this isn't generating the closing </form> tag where <% end %> is located. (I know there is now submit button in the form, this does not affect the missing </form>.)
Is this a bug? or is there something that I'm doing wrong?
This is almost certainly happening as a result of invalid HTML somewhere on the page. Run it through the validator, until it's all passing, and I bet the problem goes away...
I had the same issue. It happened to me because I didn't close one div tag properly inside the forms.

Rails 3 - button_to update same page with controller#method

In my project I have the following form_tag to select a Site
<%= form_tag({:controller => "hvacs", :action => "index"}, :method => "get") do %>
<div class="field">
<%= select :p, :site_sel, #user_sites.map{|s| [s.name, s.id]} %>
</div>
<div class="actions">
<%= submit_tag("Select site") %>
</div>
<% end %>
This form_tag updates the index page through calling its method in the controller again.
I have the following button_to
<td><%= button_to 'Select', {:controller => "hvacs", :action => "select"}, :method => "get" %></td>
I would like to achieve a similar update with this as above rather than redirect to a new page with "select_path" etc, but the above does not seem to work.
How can I achieve this? Cheers!
OK, this looked so much like my AJAX problem, I tried to make it one!
I think all you need is a simple render statement in your select action
render :index
or
render :action => 'index'
But see http://guides.rubyonrails.org/layouts_and_rendering.html#using-redirect_to for more.
The following solution worked. Apologies if I was not so clear on what I was looking for.
<%= button_to 'Select', review_hvacs_path(:h => hvac, :a => params[:a], :s => params[:s]) %>
I was trying to pass parameters with the button, while staying on the review page.

link_to_function does not react to click in rails 3.1.0 & simple_form

Here is the code in rfqs/_form_new.html.erb to add a selection box for standard.
<%= simple_form_for #rfq do |f| %>
<div id="std">
<%= render :partial => 'standards/standards', :collection => #rfq.standards, :locals => { :f => f } %>
</div>
<%= link_to_function "Add Std", nil do |page| %>
page.insert_html :bottom, :std, :partial => 'standards/standards'
<% end %>
<% end %>
The html source code has # after href and cause no reaction for clicking the link.
Add Std
The _standards.html.erb partial looks like:
<%= f.association :standards, :collection => Standard.active_std.all(:order => 'name'), :label_method => :name, :value_method => :id %>
Any thoughts about missing link after href? Thanks.
I don't believe 3.1's link_to_function works the same way as older versions; I don't see anything in the source that utilizes a block.
This seems in keeping with using unobtrusive JavaScript. The Rails pulls related to accepting a block seem more related to link text rather than injecting JS.

form_for should go to create in the controller but it doesn't

I am new to rails and just wrote a pretty complex for that updates the child elements of a video model I created.
The problem is, when I click the submit buttons it should go to the update function in the controller but instead it does nothing.
Here is my code:
<%= form_for :video, :url => video_path(#video), :html => { :method => 'put' } do |f| %>
.
.
.
<p><%= submit_tag "Update video" %></p>
<% end %>
What am I doing wrong?
:method => 'put' is not :html option so try this:
<%= form_for :video, :url => video_path(#video), :method => 'put' do |f| %>
.
.
.
<p><%= submit_tag "Update video" %></p>
<% end %>
OK, I found out what the problem was. In my routes file the rout for the video path was directing video/:id to a different location. after commenting that line it got to the update function.

Ajax form not showing up with ruby on rails form_remote_tag

This is all new territory for me, but I am working through a Rails book that was written before start_form_tag was deprecated and I am running into problems with the books example code using remote_form_tag. I have the other forms working but can't get this one up and running. Here's the code:
<h1>Categories</h1>
<ul id="category_list">
<%= render :partial => 'category', :collection => #categories %>
</ul>
<br/>
<p id="add_link"><%= link_to_function("Add a category", "Element.remove('add_link');
Element.show('add_category')") %></p>
<div id="add_category" style="display:none;">
<%= form_remote_tag(:url => {:action => 'new'},
:update => "category_list",
:position => :bottom,
:html => {:id => 'category_form'}) %>
Name: <%= text_field "category", "name" %>
<%= submit_tag 'Add' %>
<%= end_form_tag %>
</div>
This is exactly how it appears in the book, and doesn't compile. I've tried changing to match the form_tag blocks but the form enclosed by the "add_category" div never shows up.
Thanks!
UPDATE: Just found that it doesn't appear that the prototype script is not getting loaded.
both the remove and show methods on Element are showing up as undefined in Firebug. I am not sure why it is not showing up though.
I left out the = sign when including the javascript libraries in standard.html
Line should be this:
<%= javascript_include_tag :defaults %>
Vote to close this question?

Resources