I received a syntax error message
<%= calendar_date_select_tag 'e_date', I18n.l( Date.today , :format=>:default),:year_range => 15.years.ago..5.years.from_now, :readonly=>true, :popup=>"force",
{:onchange => "#{remote_function(
:url => { :action => 'report_new' },
:with => "'start_date='+s_date+'end_date='+e_date+'&batch_id='+#{#batch.id}",
:before => "Element.show('loader')",
:success => "Element.hide('loader')" )}" }%>
try this ...
:onchange => remote_function(:url => {:controller => 'controller', :action => 'action'})
or
Dont mix your view/html with javascript(forget obstrusive javascript)
instead,there is one more cleaner way....
<%= select_tag :variable, options_from_collection_for_select(:all, :id, :name), :onchange => 'your_onchange_handler()' %>
<script type='text/javascript'>
$(document).ready(function(){
function your_onchange_handler(){
//do what u want to do when select changes
}
})//document ready ends
</script>
Related
I'm currently trying to convert an ERB layout to HAML.
This is the error I keep receiving:
index.html.haml:18: syntax error, unexpected ')'
));}\n #{_hamlout.format_...
Here is the HAML page:
.row-fluid
.span6
%h2 Todo List
.span6
%h2{:style => "text-align:right;"} <script>document.write(today)</script>
%hr.divider
.row-fluid
.span6
%h2.small_head New Task
= render :partial => 'layouts/form_errors', :locals => {:object => #list}
.form
= form_for :list, :url => {:controller => 'lists', :action => 'create'} do |f|
= label_tag :list_name, "Title", :class => 'header_label'
I have also tried this as a variation:
= form_for(:list, :url => {:controller => 'lists', :action => 'create'}) do |f|
= label_tag(:list_name, "Title", :class => 'header_label')
Neither work and both generate the same error message, and help greatly appreciated.
You need to indent the code in the do block. This should work:
= form_for :list, :url => {:controller => 'lists', :action => 'create'} do |f|
= label_tag :list_name, "Title", :class => 'header_label'
I have this HAML
-content_for :primary_content do
#available-disclosures-container
.message-container.information-container
%h3=(t "headings.influencers.disclosures.new")
%p=raw((t "influencers.instructions.disclosures.new"))
=render "sidebar/disclosures/list", :disclosures => Disclosure.basics, :show_link => true, :selectable => true, :usable => false
#disclosure-form-container{:style => "display:none;"}
= form_for([:sidebar,#disclosure], :html => {:id => "disclosure-form", :remote => true}) do |f|
I am not sure why, but this last line:
= form_for([:sidebar,#disclosure], :html => {:id => "disclosure-form", :remote => true}) do |f|
is causing this error:
undefined method `model_name' for NilClass:Class
and
6: =render "sidebar/disclosures/list", :disclosures => Disclosure.basics, :show_link => true, :selectable => true, :usable => false
7:
8: #disclosure-form-container{:style => "display:none;"}
9: = form_for([:sidebar,#disclosure], :html => {:id => "disclosure-form", :remote => true}) do |f|
10: %p
11: =f.label :display_as, (t :select_disclosure_type)
12: =f.select :display_as, options_from_collection_for_select(Disclosure.basics, :display_as, :name, f.object.display_as)
Any idea what element is causing this problem?
Thanks!
This looks wrong:
= form_for([:sidebar, #disclosure]) do |f|
It looks like you're trying to generate the route by using the sidebar symbol which would need to be an instance of a model which disclosure belongs to in order to work.
Hard to know for sure but maybe this is what you're looking for:
= form_for(#disclosure), :url => [:sidebar, #disclosure] do |f|
I would like to know how can I pass a ruby variable inside an observe_field method.
I have the following:
<% action_parameter = params[:action] %>
<%= observe_field :car_type,
:url => { :controller => 'cars',
:action => :display_subtypes },
:with => "'id=' + value + '&somevalue=' + action_parameter"
%>
'action_parameter' is a variable and I would like to pass its value in the observe_field method but the code above does not seem to work.
Any suggestion?
try this
<% action_parameter = params[:action] %>
<%= observe_field :car_type,
:url => { :controller => 'cars',
:action => :display_subtypes },
:with => "'id=' + value + '&somevalue=#{action_parameter}'"
%>
Ruby variable will work in <% .... %>
you can use interpolation , Try this :
<%= observe_field :car_type,
:url => { :controller => 'cars',
:action => :display_subtypes },
:with => "id=#{value}&somevalue=#{action_parameter}"
%>
I have a bootstrap dropdown menu in my application that is working great, except that when I click on any of the input fields the dropdown menu fades out. I know about the javascript function $('.dropdown-menu').find('form').click(function (e) {
e.stopPropagation();
}); but in my case it doesnt seem to be doing anything.
Here is my code:
%li.dropdown
%a.dropdown-toggle{"data-toggle" => "dropdown", :href => "#"}
Sign In
%span.caret
.dropdown-menu
%form{"accept-charset" => "UTF-8", :action => "/users", :method => "post", :style => "margin: 0px"}
%div{:style => "margin:0;padding:0;display:inline"}
%input{:name => "utf8", :type => "hidden", :value => "✓"}/
%input{:name => "authenticity_token", :type => "hidden", :value => "4L/A2ZMYkhTD3IiNDMTuB/fhPRvyCNGEsaZocUUpw40="}/
%fieldset.textbox{:style => "padding:10px"}
%input{:placeholder => "Username", :style => "margin-top: 8px", :type => "text"}/
%input{:placeholder => "Passsword", :style => "margin-top: 8px", :type => "password"}/
.divider
%input.btn-primary{:name => "commit", :type => "submit", :value => "Log In"}/
Can anyone please point at my error? Why is this not working? Thank is advance.
Try this instead:
$('.dropdown input, .dropdown label').click(function(e) {
e.stopPropagation();
});
<p>Song Name:<%= text_field :songlists, :song_name, :id => "songlists_" + section.id.to_s + "_song_name" %></p>
<%= auto_complete_field "songlists_" + section.id.to_s + "_song_name", :method => :get,
:with => "'search=' + element.value", :url => formatted_songlists_path(:js) %>
<p>Artist:<%= text_field :songlists, :artist, :id => "songlists_" + section.id.to_s + "_artist" %></p>
<%= observe_field ("songlists_" + section.id.to_s + "_song_name", :update => "songlists_" + section.id.to_s + "_artist", :with => "element.value" , :url => { :controller => :songlists, :action => "get_artist" } ) %>
I have the auto-complete-field working fine, and the observe-field is triggering according to firebug, but I'm unsure how to update the text-field from the observe-field.
I either need to get the ID that the auto-complete finds, or even the text entered so that I can pass it into the :url of the observe-field.
Any ideas?
Can you walkthrough what you want this code to do?
I'm trying to get the response from the auto-complete field, to update another text-field with the results. I have the responses working now in firebug, but I can't seem to get it to update the box with the results.
<p>Song Name:<%= text_field :songlists, :song_name, :id =>
"songlists_" + section.id.to_s + "_song_name" %></p>
<%= auto_complete_field "songlists_" + section.id.to_s +
"_song_name", :method => :get,
:with => "'search=' + element.value",
:url => formatted_songlists_path(:js) %>
<p>Artist:<%= text_field :songlists, :artist %></p>
<%= observe_field "songlists_" +section.id.to_s + "_song_name",
:frequency => 0.5,
:url => { :controller => :songlists,
:action => :get_artist },
:update => "songlists_artist",
:with => "song_name" %>
controller code
def get_artist
#songlist = Songlist.find(:all, :conditions => ['name = ?', params[:song_name]])
if !#songlist.empty?
render :update do |page|
page.replace_html 'songlists_artist', :partial =>
'get_artist', :object => #songlist
end
end
end
In firebug I see this response
try {
Element.update("songlists_artist", "Robbie Williams");
} catch (e) { alert('RJS error:\n\n' + e.toString());
alert('Element.update(\"songlists_artist\", \"Robbie Williams\");');
throw e }
But it is not updating my text-field, any ideas?