Simple_form how to make accept terms checkbox inline - html

<p><%= f.input :terms, :as => :boolean, :label => false, :boolean_style => :inline %>
Accept <%= link_to "Terms of use", terms_path,:remote => true %>
and <%=link_to "privacy Policy", privacy_path, :remote => true%></p>
It ends up looking like this
What is the best way to line them up on the same line.

Here's a rather simple way:
<%= content_for(:the_links) do %>
Accept <%= link_to "Terms of use", terms_path,:remote => true %>
and <%=link_to "privacy Policy", privacy_path, :remote => true%>
<% end %>
<%= simple_form_for #user do |f| %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.input :terms, :as => :boolean, :label => content_for(:the_links)%>
<% end%>

Ensure the checkbox and text are small enough to fit in one row inside the container, then set display: inline; or float:left;

Try using wrapper_html like this:
<p>
<%= f.input :terms,
:as => :boolean,
:label => false,
:boolean_style => :inline,
:wrapper_html => { :style => 'display: inline' }
%>
Accept <%= link_to "Terms of use", terms_path,:remote => true %>
and <%=link_to "privacy Policy", privacy_path, :remote => true%>
</p>

Related

How do I get select_tag to display text in front of the parameter?

I want to display "Year: " inside the 'year' dropbox shown in the image below. How do I append text to the parameter field?
I'm using a select_tag as shown below:
<%= form_tag results_path, :method => 'get' do %>
<%= select_tag :season_year, options_for_select(#tournaments.order(season_year: :desc).collect{ |u| [u.season_year] }.uniq, session[:season_year]), class: "btn btn-outline-primary", :onchange => "this.form.submit();" %>
<%= select_tag :tournament, options_for_select(#tournaments_filtered.order(tournament_date: :desc).collect{ |u| [u.lake_name, u.id] }, session[:tournament]), class: "btn btn-outline-primary", :onchange => "this.form.submit();" %>
<%= select_tag :table_select, options_for_select(#result_options, session[:table_select]), class: "btn btn-outline-primary", :onchange => "this.form.submit();" %>
<% end %>
You can use the include_blank option to add a dud option.
ie add include_blank: "Year:"
See docs for more details

How to make only textbox less wide?

I want the text boxes to be less wide, maybe half the size? How would I do this? Here is what it looks like
I tried using col-xs-5 but that would ruin the vertical alignment.
<h2>
Add User
</h2>
<div class="user">
<div class="container-fluid">
<%= form_for(#user) do |f| %>
<%= f.label :first_name, :class => 'col-form-label' %>
<%= f.text_field :first_name, :placeholder => "First name", :class => 'form-control', :required => 'required' %><br>
<%= f.label :last_name, :class => 'col-form-label' %>
<%= f.text_field :last_name, :placeholder => "Last name", :class => 'form-control', :required => 'required' %><br>
<%= f.label :email, :class => 'col-form-label' %>
<%= f.email_field :email, :placeholder => "Email", :class => 'form-control', :required => 'required' %><br>
<%= f.label :password, :class => 'col-form-label' %>
<%= f.password_field :password, :placeholder => "Password", :class => 'form-control', :required => 'required' %><br>
<%= f.label :password_confirmation, "Confirm password" %>
<%= f.password_field :password_confirmation, :placeholder => "Confirm password", :class => 'form-control', :required => 'required' %><br>
<%= f.submit "Add", :class => "btn btn-lg btn-primary" %>
<% end %>
</div>
</div>
.container-fluid is a width of 100%.
So wrap the form in another div inside the container-fluid and set a max-width to like 500px. That should squeeze the form smaller. Play around with that.
Apply a width (or max-width) to the text boxes using CSS. That will only impact those elements and not the container around them.

ruby on rails wrap block of code in link_to

Hello I have this link_to and I can't figure out how to wrap a block of html code in it such that the div inside the link_to becomes a link. I have this code:
<%= link_to #favorites[0].name, {:controller => "events", :action => "search", :category => #favorites[0].name} %>
I have tried using "do" then <%end%> but I can't make it work.
<%= link_to #favorites[0].name, {:controller => "events", :action => "search", :category => #favorites[0].name} do %>
<div> CODE HERE</div>
<%end%>
Any ideas on how to do this? I do not understand the syntax.
You need to give only path with link_to when using the block.
<%= link_to({:controller => "events", :action => "search", :category => #favorites[0].name}) do %>
<div>
<%= #favorites[0].name %>
</div>
<%end%>

Rails ERB form fields rendered hidden

I have this form, and all of its element are rendered with the type="hidden", I don't know why this happens.
<%= form_for(:session, url: sessions_path) do |f| %>
<%f.text_field :username, :value => "Enter your user name", :class => "username-label" %>
<span class="email-icon"></span>
<% f.text_field :password, :value => "Enter your password", :class => "password-label" %>
<% f.submit "LOG IN", :class => "login-button" %>
<% end %>
With <% you are just executing the helpers. You need to use <%= ... %> to output the result of those helper calls:
<%= form_for(:session, url: sessions_path) do |f| %>
<%= f.text_field :username, :value => "Enter your user name", :class => "username-label" %>
<span class="email-icon"></span>
<%= f.text_field :password, :value => "Enter your password", :class => "password-label" %>
<%= f.submit "LOG IN", :class => "login-button" %>
<% end %>

Ruby on Rails link_to

I am using link_to with some HTML elements and this is what I have :
<% link_to "", { :controller => "posts" }, :id => "posts", :class => "read-more" %>
But I want it that it will link to the posts with the id that each post has, any help would be most appreciated.
Thank You
config/routes.rb
resources :posts
<% #posts.each do |post| %>
<%= link_to "View post", post_path(post), :id => "posts", :class => "read-more" %>
<% end %>
Your hash is missing a few params...
<% link_to "", { :controller => "posts", :action => "show", :id => post.id}, :id => "posts", :class => "read-more" %>
But I recommend
<% link_to "", post_path(post), :id => "posts", :class => "read-more" %>
I think what you are asking is this. You have an array or active record relation #posts which you want to show in a webpage with links to each post. If I'm right you can do
<% #posts.each do |post| %>
<%= link_to "", { :controller => "posts" }, :id => post.id, :class => "read-more" %>br>
<% end %>
But you have to specify the action which will be triggered when the link is clicked.
I think this should work
<% #posts.each do |post| %>
<%= link_to "", { :controller => "posts" , :action => :show}, :id => post.id, :class => "read-more" %>br>
<% end %>
How about this?
<% #posts.each do |post| %>
<%= link_to "POST", post_path(post), :id => post.id %>
<% end %>