I'm trying to display a delete button only if the current user is the "host" but the button is hidden even if the user id for the host matches the user id for the guest
<%= link_to "X" , "/songs?name=#{s.name}&party_profile_id=#{s.party_profile_id}&commit=X", :remote => true, :class => "btn btn-inverse btn-small refreshbutton", :style => "display:none" unless #current_user.id == #party_profile.host %>
Am I using the wrong syntax? Is there a better way to conditionally display items?
You could switch to only render it, rather than toggling the css class (unless your application would need to toggle it client side for some reason).
<% if #current_user.id == #party_profile.host %>
<%= link_to "X" , "/songs?name=#{s.name}&party_profile_id=#{s.party_profile_id}&commit=X", :remote => true %>
<% end %>
Your condition would apply to the link itself, not the style attribute.
Do this instead:
<%= link_to "X" , "/songs?name=#{s.name}&party_profile_id=#{s.party_profile_id}&commit=X", :remote => true, :class => "btn btn-inverse btn-small refreshbutton", :style => "#{'display:none;' unless #current_user.id == #party_profile.host}" %>
shouldn't it be
if #current_user.id == #party_profile.host ?
Edit:
you don't need to set the style to display none. The if statement will handle whether it is rendered in the view.
Related
How can I make the new_value_path actually be a submit button that creates a new value instead of just refreshing back onto itself?
My current new.html.erb:
<h1>New Value</h1>
<%= render 'form' %>
<%= link_to new_value_path, class: 'btn' do %>
<b><span class="glyphicon glyphicon-plus"</span></b>
<% end %>
I want to keep the class: 'btn' and the span class="glyphicon glyphicon-plus" I think it has something to do with CRUD, but I haven't found an answer that specifically deals with including a class and a span.
I had to solve the answer in the _form itself using f.submit
I am using Rails 3.1x, SimpleForm 2.1, and Bootstrap 2.2.x, and I want to change the position of the hint text on some of my forms.
Currently if I use code such as the following (this is a simplified version)
<%= simple_form_for #user, :html => { :class => 'form-horizontal' } do |f| %>
<%= f.input :name, :hint => 'this should be your first name' %>
..
..
I will get a form looks like this
However, I would like it to look like this.
Any thoughts?
I am not sure its works well but try this , in your form field add class
<%= f.input :name, :hint => 'this should be your first name' , :class => "someclass"%>
and in application.css
.somecalss
{
width:somevalue;
}
I have a form and I'm setting a field to be required before submitting, however nothing is showing up when I hit the Search button. What do I need to do to style the form?
<%= form_tag search_path, :method => :get, class: "form-search-home" do %>
<%= text_field_tag :q, :class => "term form-control" %>
<%= text_field_tag :loc, :class => "loc form-control", :required => true %>
<%= button_tag :type => :submit, :class => "btn" do %>Search<% end %>
<% end %>
Thanks!
nothing is showing up when I hit the Search button
The problem here is likely a Rails / HTML issue than CSS (as mentioned in your question)
Syntax
As pointed out in the comments, you have a series of problems with your code syntax, specifically with submit_tag & text_field_tag:
<%= form_tag search_path, method: :get, class: "form-search-home" do %>
<%= text_field_tag :q, nil, class: "term form-control" %>
<%= text_field_tag :loc, nil, class: "loc form-control", required: true %>
<%= submit_tag "Search", class: "btn" %>
<% end %>
This should fix any of the syntax issues you have on your form, allowing it to submit. The reason why it doesn't at the moment is likely down to the syntax being incorrect. If you use the above code, it should render the form correctly, allowing you to submit it as required!
--
CSS
CSS is cascading style sheets - meaning they're only meant to style your page. They can't fix any syntax, backend or HTML rendering issues - only how the HTML appears in the browser
If you've still got trouble with your CSS, you'll be best styling the form with the inputs inheriting from the main class styling:
#app/assets/stylesheets/application.css
form {
/* form code */
}
form input.required {
/* required form element styling */
}
Does your form code generate a valid HTML?
As far as I see from documentation, text_field_tag method has three arguments:
text_field_tag(name, value = nil, options = {})
Your example ommits the second argument (value), so may be that is the case. Wonder if this could help:
<%= text_field_tag :loc, nil, :class => "loc form-control", :required => true %>
I am writing a form with three text input fields. I have used text_field_tag to create them
<%= text_field_tag(:input_first) %>
<%= text_field_tag(:input_second) %>
<%= text_field_tag(:input_first) %>
Am using bootstrap css. I want to make the second input larger than the first and the third input. How can I achieve that?
I have tried the below, and even more and the input field size is not changing.
first
<%= text_field_tag(:input_second, :input_html => { :class => "input-large"}) %>
second
<%= text_field_tag(:input_second, nil, :class => "input-large") %>
third
<%= text_field_tag(:input_second, nil, :size=> 30) %>
fourth
<span class="input-large">
<%= text_field_tag(:input_second) %>
</span>
What wrong am I doing? Am a beginner in rails/css/html
ps: should I use text_field_tag or text_field ?
Bootstrap utilizes specific classes to control the width of input elements:
In a Rails template, you'd invoke a text_field_tag in the following manner:
<%= text_field_tag('input_second', nil, class: 'input-large') %>
The code below creates a form and styles the "submit" button according to some css ("button"). The problem is, when the page renders, it shows the normal rails submit tag button on top of the customized "button" css. How do I mute or disable the visual aspects of the rails submit tag button while still making it submit the form?
=form_tag new_site_url, :method => :get do
=text_field_tag :homepage,'', type: "text", class: 'text'
%button
=submit_tag "GO!"
Could you do this :
=form_tag new_site_url, :method => :get do
=text_field_tag :homepage,'', type: "text", class: 'text'
=submit_tag "GO!", class: 'button'
and set the css style for the button?
It better to do this :
=form_tag new_site_url, :method => :get do |f|
=f.text_field '', type: "text", class: 'text'
=f.submit "GO!", class: 'button'
Another way is (rails 4.1)
<%= submit_tag("Submit", :class => "btn btn-warning" ) %>
Here is where you go to find answers http://api.rubyonrails.org/
and if you are working in form_for you would do
<%= f.submit("Submit", class: "btn btn-default" ) %>
I'm using old school ruby(1.8.7) and rails(2.3.5)
heres what my submit tags look like for custom css styling :
<%= submit_tag("Edit", :style => "width:30px;") %>
where "Edit" is the text that appears on the button, and "width:30px;" is my styling. you can also cascade the stylings :
<%= submit_tag("Edit", :style => "width:30px;color:blue;") %>
You can add a style key to the hash
<p><%= submit_tag l(:button_apply), :class => 'btn btn-default btn-sm', :name => 'submit', :style => 'margin-left: 42px' %></p>