I don't know Ruby but I'm having this problem with my application. Somebody can help me?
ActionView::TemplateError (can't convert nil into String) on line #7
4: <h3><span><%= opinion.opinion %></span>: <%= opinion.keywords.sort.join(' / ').upcase %> </h3>
5: <div class="original">Estado original: <span class="pos"><%= opinion.opinion %></span></div>
6: <%#= highlight(simple_format(highlight_ontology(opinion)), opinion.keywords, :highlighter => '<em>\1</em>') %>
7: <%= simple_format(highlight_ontology(opinion)) %>
8: <%= button_to_remote('POSITIVO', {:url => url_for(opinion), :method => :put, :with => '"opinion[opinion]=POSITIVE"' }, :class => :positive) %>
9: <%= button_to_remote('OBJETIVO', {:url => url_for(opinion), :method => :put, :with => '"opinion[opinion]=OBJECTIVE"' }, :class => :objective) %>
10: <%= button_to_remote('NEGATIVO', {:url => url_for(opinion), :method => :put, :with => '"opinion[opinion]=NEGATIVE"' }, :class => :negative) %>
Thanks!
Using (variable || "") instead of just the variable should make it default to an empty string.
This technique is called null(or nil) coalescing.
Related
I would like to pass a parameter with this link_to helper. How do I do that?
<%= link_to ('/my_controller/my_action') do %>
<div>haha</div>
<% end %>
The original code I had used the standard text link:
<%= link_to("link text", {:controller => 'my_controller', :action => 'my_action', :id => my_id}) %>
Just like in your second example:
<%= link_to({:controller => 'my_controller', :action => 'my_action', :id => my_id}) do %>
My text goes here
<% end %>
If you have a path helper for this (i.e. if it's something like PostsController's show action) then you could do:
<%= link_to post_path(my_id) do %>
My text goes here
<% end %>
From my understanding you want to pass options to the link_to helper when using a block.
From the documentation at http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
This is possible with the following format
link_to(options = {}, html_options = {}) do
# name
end
To give you an example and using the code you provided:
<%= link_to({:controller => 'my_controller', :action => 'my_action', :id => my_id}) do %>
<div>haha</div>
<% end %>
I updated to Rails4, and am now getting "wrong number of arguments (3 for 2)".
.col-md-6.col-md-offset-3
= form_for(resource, :as => resource_name, url: session_path(resource_name), :html => { :class => "search-form home-search"}) do |f|
= f.email_field :email, :id => 'beta_form', :class => 'beta_form', :placeholder => 'Email'
= f.password_field :password, :id => 'beta_form', :class => 'beta_form', :placeholder => 'Password'
= f.submit "Sign In", :class => 'btn btn-primary btn-lg btn-block beta_submit center-block'
= render "devise/shared/links"
All set. For some reason, I had to delete gem 'meta-search' after upgrading.
Is this correct to send an ajax request?
This code isn't working, what do I need to change here? Any better way to send an ajax form?
<%= form_tag item_create_path, :remote => true, :id => 'create_item' do %>
<p>
<b> <%= label_tag :"Name" %></b> <%= text_field_tag :name, nil, :maxlength => 40, :size => 70 %>
<b> <%= label_tag :"Date" %></b> <%= text_field_tag :date, nil, :maxlength => 10, :size => 10, :value => Time.now.utc.strftime("%Y-%m-%d") %>
<b> <%= label_tag :"Time" %></b> <%= text_field_tag :time, nil, :maxlength => 10, :size => 10, :value => Time.now.localtime.strftime("%H:%M:%S") %>
</p>
<p>
<b> <%= label_tag :Description %></b> <%= text_field_tag :description, nil, :maxlength => 50, :size => 50 %>
</p>
<%= hidden_field_tag :type, nil, :value => "new" %>
<p class="button"><%= submit_tag " Create ",:onclick=>"javascript:submitForm()" %></p>
<% end %>
function submitForm() {
$.ajax({type:'POST', url: '/item/create', data:$('#create_item').serialize(), success: function(response) {
$('#create_item').find('#item').html(response);
}});
return false;
}
Use this it will sure work
<%= form_for(:customer, :url => {:controller => "subscribers", :action => "change_password"}, :html => {:id => 'edit_password_form', :method => :get, :onsubmit => "return false;"}) do |f| %>
<%= hidden_field_tag "ids", :id => "ids"%>
<div class="ports-fields">
<div class="pass">
<label style="margin-top:4px;">Password</label>
<%= f.password_field :password, :class=> 'fields', :placeholder => 'Password' %>
</div>
<div class="pass">
<label>Confirm Password</label>
<%= f.password_field :password_confirmation, :class=> 'fields', :placeholder => 'Password Confirmation' %>
</div>
<div class="change-pass-btn-submit">
<%= submit_tag "CHANGE PASSWORD", :id => "edit_password_btn" %>
</div>
<!--modify ports ends-->
</div>
<% end %>
and jquery code for this
<script type="text/javascript">
$("#edit_port_btn").click(function() {
var container = $("#info");
$("#edit_port_form").submit(function() {
$(this).unbind('submit').ajaxSubmit({
success: function(data) {
container.html(data);
hudMsg('success', 'Modify ports successfully.');
}
})
});
});
</script>
And enjoyy....
View :
<%= link_to "Link", {:action => "AjaxView",:col => "colname"}, :update => "Ajaxcall", :remote => true %>
Controller:
def AjaxView
#vars= Var.find(:all,:conditions => { :varName=> "one" },:select=>(params[:col]))
respond_to do |format|
format.js { render :layout=>false }
end
end
AjaxView.js
$("#3").text("<%= escape_javascript(render(:partial => "var", :collection => #vars)) %>");
_var.html.erb
<%= var.col1 %>
I am getting following error:
ActionView::Template::Error (missing attribute: col1 ):
1: <%= var.col1 %>
<%= #var[0].col %> is the right answer
I installed the gem client_side_validations, did everything exactly according to the manual, for greater certainty, I checked it on a test project, it worked, but when i migrate it to my project it gave this error:
undefined method `validate_options' for #<User:0xb67365fc>
this is the form code:
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :validations => true, :html => {:id => 'commentform'}) do |f| %>
<%= f.input :name, :label => t('general.name') %>
<%= f.input :last_name, :label => t('general.last_name') %>
<%= f.input :email, :label => t('general.email') %>
<%= f.input :phone, :label => t('general.phone') %>
<% if #user.password_required? %>
<%= f.input :password, :label => t('general.password') %>
<%= f.input :password_confirmation, :label => t('general.password_confirm') %>
<%= f.hidden_field :is_anonym, :value => false %>
<% end %>
<br/>
<%= f.button :submit, :label => t('general.button') %>
<% end %>
anyone help me..
For what its worth I've rewritten the ClientSideValidation gem completely. The previous version I wrote at the DNC had some pretty big issues.
Feel free to check out the 3.0 rewrite: https://github.com/bcardarella/client_side_validations