Am trying autocomplete in rails. since am noob in rails am not able to convert this slim code to erb so can anybody help me out!!!
first slim file
# app/views/books/index.html.slim
= form_tag books_path, class: "form-inline", method: :get do
.form-group
= text_field_tag :query, params[:query], class: "form-control"
'
= submit_tag "Search", class: "btn btn-primary"
- if params[:query].present?
'
= link_to "clear", books_path
second slim file
#app/views/layouts/application.html.slim
= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.9.3/ typeahead.min.js"
third slim file
# app/views/books/index.html.slim
= form_tag books_path, class: "form-inline", method: :get do
.input-group.input-group-lg
- if params[:query].present?
.input-group-btn
= link_to "clear", books_path, class: "btn btn-default"
= text_field_tag :query, params[:query], class: "form-control", id: "book_search", autocomplete: "off"
.input-group-btn
= submit_tag "Search", class: "btn btn-primary"
First:
<%=form_tag books_path, class: "form-inline", method: :get do %>
<div class="form-group">
<%= text_field_tag :query, params[:query], class: "form-control" %>
<%= submit_tag "Search", class: "btn btn-primary" %>
<% if params[:query].present? %>
<%= link_to "clear", books_path %>
<% end %>
</div>
Second:
<%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.9.3/ typeahead.min.js" %>
Third:
<%= form_tag books_path, class: "form-inline", method: :get do %>
<div class="input-group input-group-lg" >
<% if params[:query].present? %>
<div class="input-group-btn">
<%= link_to "clear", books_path, class: "btn btn-default" %>
</div>
<%= text_field_tag :query, params[:query], class: "form-control", id: "book_search", autocomplete: "off" %>
<div class="input-group-btn">
<%= submit_tag "Search", class: "btn btn-primary" %>
</div>
<% end %>
</div>
You can always verify it here - http://html2slim.herokuapp.com/
Enjoy.
Related
I am developing a simple account registration and update form and I have recently entered a parameter that can have two possible choices, in my case one problem occurred:
Problem:
<div class="tag">
<%= f.label :ruolo %><br />
<%= f.radio_button_tag(:ruolo, "admin") %>
<%= f.label_tag(:ruolo_admin, "admin") %>
<%= f.radio_button_tag(:ruolo, "user") %>
<%= f.label_tag(:ruolo_user, "user") %>
</div>
if I leave the code like this it gives me an error like:
NoMethodError in Devise::Registrations#edit
undefined method `radio_button_tag 'for # <ActionView :: Helpers :: FormBuilder: 0x00007fd6fd02f478>
this is the form:
<div class="row">
<div class="col s12 l6 offset-l3">
<br>
<br>
<h4 class="center">Registrazione</h4>
<br>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name, autofocus: true %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email %>
</div>
<div class="field">
<%= f.label :ruolo %><br />
<%= f.radio_button_tag(:ruolo, "admin") %>
<%= f.label_tag(:ruolo_admin, "admin") %>
<%= f.radio_button_tag(:ruolo, "user") %>
<%= f.label_tag(:ruolo_user, "user") %>
</div>
<div class="field">
<%= f.label :password %>
<% if #minimum_password_length %>
<em>(<%= #minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<br>
<div class="actions">
<%= f.submit "Iscriviti", class: "waves-effect waves-light btn btn-devise" %>
</div>
<br>
<% end %>
<%= render "devise/shared/links" %>
</div>
</div>
Controller code:
class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
#roles=Role.all
devise_parameter_sanitizer.permit(:sign_up, keys: [:name,:ruolo])
devise_parameter_sanitizer.permit(:account_update, keys: [:name,:ruolo])
end
end
radio_button_tag is not an instance method of ActionView :: Helpers :: FormBuilder, but rather ActionView::Helpers::FormTagHelper
So instead of calling it like:
<%= f.radio_button_tag(:ruolo, "admin") %>
You simply call it like:
<%= radio_button_tag(:ruolo, "admin") %>
For more details on this method please check the docs:
https://apidock.com/rails/v6.0.0/ActionView/Helpers/FormTagHelper/radio_button_tag
I need to get the value after it is created, just below the section "NEW"
Below is the image I intended to do, and after the data was created I wanted it right there
phrases_term_controller.rb
class PhrasesTermsController < ApplicationController
before_action :authenticate_user!
before_action :set_term
def new
#phrases_term = PhrasesTerm.new
end
def create
#phrases_term = #term.phrases_terms.new(phrases_term_params)
if #phrases_term.save
redirect_to term_phrases_term_path(#term, #phrases_term), notice: "Phrases_Term was successfully created"
else
render "new"
end
end
def show
#phrases_term = PhrasesTerm.find(params[:id])
end
private
def phrases_term_params
params.require(:phrases_term).permit(:term_id, :phrase_id)
end
def set_term
#term = Term.find(params[:term_id])
end
end
View
phrases_term
new.html.erb
<h1><%= I18n.t("pages.phrases_term.new.title") %></h1>
<%= render 'form', phrases_term: #phrases_term %>
_form.html.erb
<%= form_with scope: :phrases_term, url: term_phrases_terms_path, local: true do |form| %>
<% if phrases_term.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(phrases_term.errors.count, "error") %> prohibited this phrase from being saved:</h2>
<ul>
<% phrases_term.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= form.label :term_id %> :
<%= form.number_field :id %>
</div>
<div class="dropdown">
<button class="dropbtn">Phrase</button>
<div class="dropdown-content">
<a><%= form.select :phrase_id, Phrase.all.collect { |p| [ p.id ] }, include_blank: true %></a>
</div>
</div>
<div class="actions">
<%= form.submit %>
</div>
<% end %>
Term:
_form.html.erb
<%= form_with(model: term, local: true) do |form| %>
<% if term.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(term.errors.count, "error") %> prohibited this term from being saved:</h2>
<ul>
<% term.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= form.label :word %>
<%= form.text_field :word %>
</div>
<div class="field">
<%= form.label :meaning %>
<%= form.text_field :meaning %>
</div>
<div class="field">
<%= form.label :reading %>
<%= form.text_field :reading %>
</div>
<div class="actions">
<%= form.submit %>
</div>
<% end %>
I am not sure I have provided all the necessary information, if I want to add some more information, please comment below. ---Thank You.----
I have this code for a search bar in my nav bar.
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search an Artist">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
And I want it to correlate to this embedded ruby code
<%= form_tag(artists_path, :method => "get", id: "search-form") do %>
<%= text_field_tag :search, params[:search], placeholder: "Search Artists" %>
<%= submit_tag "Search", :name => nil %>
<% end %>
I tried to just remove the div class ="form-group" and submit button and then put the ruby code within the form class, but then it changes the look of it and will only work when I'm already on my artists page, I want it to work from anywhere on my site. Any suggestions on how to integrate the ruby code into the html one?
This should work:
<%= form_tag(artists_path, :method => "get", id: "search-form", html: {class: 'form-group'}) do %>
<%= text_field_tag :search, params[:search], placeholder: "Search Artists", class: "form-control" %>
<%= submit_tag "Search", :class => 'btn btn-default',:name => nil%>
<% end %>
I'm trying to use paperclip with rails 3.1 but I keep getting this routing error.
No route matches {:action=>"show", :controller=>"users"}
I followed the instructions at thoughtbot/paperclip on github.
<%= form_for :user, #user, :url => user_path, :html => { :multipart => true } do |f| %>
<% if #user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% #user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :FirstName %><br />
<%= f.text_field :FirstName %>
</div>
<div>
<%= f.label :avatar%>
<%= f.file_field :avatar %>
</div>
<div class="field">
<%= f.label :LastName %><br />
<%= f.text_field :LastName %>
</div>
<div class="field">
<%= f.label :Email %><br />
<%= f.text_field :Email %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
User.rb
class User < ActiveRecord::Base
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
end
routes.rb
City::Application.routes.draw do
resources :users
end
show.html.erb
<p id="notice">
<%= notice %>
</p>
<p>
<b>Firstname:</b>
<%= #user.FirstName %>
</p>
<p>
<b>Lastname:</b>
<%= #user.LastName %>
</p>
<p>
<b>Email:</b>
<%= #user.Email %>
</p>
<p>
<b>Avatar</b>
<%= image_tag #user.avatar.url %>
<%= image_tag #user.avatar.url(:medium) %>
<%= image_tag #user.avatar.url(:thumb) %>
</p>
<%= link_to 'Edit', edit_user_path(#user) %> |
<%= link_to 'Back', users_path %>
!UPDATE!
$ rake routes
events GET /events(.:format) {:action=>"index", :controller=>"events"}
POST /events(.:format) {:action=>"create", :controller=>"events"} new_event GET
/events/new(.:format) {:action=>"new",
:controller=>"events"} edit_event GET /events/:id/edit(.:format)
{:action=>"edit", :controller=>"events"}
event GET /events/:id(.:format) {:action=>"show", :controller=>"events"}
PUT /events/:id(.:format) {:action=>"update", :controller=>"events"}
DELETE /events/:id(.:format) {:action=>"destroy", :controller=>"events"}
root / {:controller=>"events", :action=>"index"}
/:controller(/:action(/:id(.:format)))
I believe you should use users_path (plural) and, the user routes are not in your rake output, can you check your routes file?
The error you are having is not from paperclip cos paperclip has nothing to do with that error message you are having. check your routes very well and also try to restart you sever.
I am a new Rails user and trying to integrate Paperclip into my app for the firs time. I am getting the following error message when hitting the "new post" button within my app, which is basically a blog at this point.
SyntaxError in Posts#new
Showing /Users/blanecordes/rails_projects/BoxScoreBuzz/app/views/posts/_form.html.erb where line #1 raised:
compile error
/Users/blanecordes/rails_projects/BoxScoreBuzz/app/views/posts/_form.html.erb:1: syntax error, unexpected tASSOC, expecting kEND
...end= form_for(#post), :html=> {:multipart => true} do |f| #...
^
/Users/blanecordes/rails_projects/BoxScoreBuzz/app/views/posts/_form.html.erb:1: syntax error, unexpected kDO, expecting kEND
...html=> {:multipart => true} do |f| #output_buffer.safe_conca...
^
/Users/blanecordes/rails_projects/BoxScoreBuzz/app/views/posts/_form.html.erb:35: syntax error, unexpected kENSURE, expecting $end
Extracted source (around line #1):
1: <%= form_for(#post), :html=> {:multipart => true} do |f| %>
2: <% if #post.errors.any? %>
3: <div id="error_explanation">
4: <h2><%= pluralize(#post.errors.count, "error") %> prohibited this post from being saved:</h2>
This is my current _form.html.erb code
<%= form_for(#post), :html=> {:multipart => true} do |f| %>
<% if #post.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#post.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% #post.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :content %><br />
<%= f.text_area :content %>
</div>
<div class="field">
<%= f.label 'Photo' %><br />
<%= f.file_field :photo %><br />
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Try changing the first line in _form.html.erb to:
<%= form_for(#post, :html=> {:multipart => true}) do |f| %>