I have a problem and I don't realu understand it.
I have this error :
undefined method `value' for "test":String
here my view :
<div id="search">
<%= form_for :search, url: search_path do |f| %>
<%= f.text_field :value, :class => 'form-control input-sm', :placeholder => 'Search...' %>
<%= button_tag '<i class="fa fa-search"></i>'.html_safe, :id => 'search-btn', :class => 'btn' %>
<% end %>
</div>
and here my controller :
def index
#clubs = Club.all
#search = params[:search][:value]
end
I think that the problem is about how I catch my variable :value but I don't know how to fix it.
Thanks
A quick thought is that text_field has a :value parameter to set the default value.
Try changing :value to something else
<%= form_for :search, url: {} do |f| %>
<%= f.text_field :keywords, :value => params[:keywords], :class => 'form-control input-sm', :placeholder => 'Search...' %>
<%= button_tag '<i class="fa fa-search"></i>'.html_safe, :id => 'search-btn', :class => 'btn' %>
<% end %>
Then
#search = params[:search][:keywords]
Related
I'm trying to override login page in spree using deface, but I can't access the login partial using the following code
Deface::Override.new(
:virtual_path => 'spree/shared/_login',
:name => 'override login',
:replace=> "body",
:text=> "<body><h1>loin<h1></body>",
:disabled => false
)
How ever this seems not to work for some reason, in the server output I get :
Deface: 1 overrides found for 'spree/shared/_login'
Deface: 'override login' matched 0 times with 'body'
Rendered /home/user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spree_auth_devise-3.1.0/lib/views/frontend/spree/shared/_login.html.erb (50.3ms)
Rendered /home/user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spree_auth_devise-3.1.0/lib/views/frontend/spree/user_sessions/new.html.erb within spree/layouts/spree_application (77.4ms)
I tried multiple selectors for css in the page with no result, I noticed the login partial is located in 'spree_auth_devise-3.1.0' sub directory 'not spree_frontend-3.1.0' as the rest of them, does anyone now how to deface the login page in spree or how to reference the right path for its partial ?
If you would like to replace all body, better override partial and not use Deface. It is great tool but not when you want to do so big change.
Error means that it not found body in partial, and thats true because there is no body.
You can use only
<%= form_for Spree::User.new, :as => :spree_user, :url => spree.create_new_session_path do |f| %>
<div id="password-credentials">
<p>
<%= f.label :email, Spree.t(:email) %>
<%= f.email_field :email, :class => 'form-control', :tabindex => 1, autofocus: true %>
</p>
<p>
<%= f.label :password, Spree.t(:password) %>
<%= f.password_field :password, :class => 'form-control', :tabindex => 2 %>
</p>
</div>
<p>
<%= f.check_box :remember_me, :tabindex => 3 %>
<%= f.label :remember_me, Spree.t(:remember_me) %>
</p>
<p><%= f.submit Spree.t(:login), :class => 'btn btn-lg btn-success btn-block', :tabindex => 4 %></p>
<% end %>
I have used paperclip to image uploading in rails.When i was uploading a image,i got a error like this Errno::EISDIR:
Is a directory # unlink_internal - /home/ubuntu/app/public and this happened intermittent.Anyone give me solution.
My model file
class DayCare < ActiveRecord::Base
has_attached_file :logo, :default_url => 'default.png'
# Validations
validates_attachment :logo, content_type: { content_type: /\A(image|video)\/.*\Z/ }
end
My form
<%= simple_form_for(resource, as: resource_name ,:id=>"registerform", url: registration_path(resource_name),html: { class: "form-horizontal"}) do |f| %>
<%- if resource.errors.any? %>
<%- f.object.errors.full_messages.each do |error_message| %>
<%= error_message%>
<%- end %>
<%- end %>
<%= f.input :email,required: true, autofocus: true,:placeholder => "Enter E-mail address",:label=>false,:input_html => { :class => "form-control" } %>
<%= f.input :password, required: true,:placeholder => "Choose Password",:label=>false,:input_html => { :class => "form-control" } %>
<%= f.input :password_confirmation, required: true,:placeholder => "Confirm Password",:label=>false,:input_html => { :class => "form-control" } %>
<%= f.simple_fields_for :day_care, #user.build_day_care do |d| %>
<%= d.input :name, :input_html => { :class => "form-control" },:placeholder => "Child Care Center",:label=>false %>
<%= d.input :address, :input_html => { :class => "form-control" },:placeholder => "Street Address",:label=>false %>
<%= d.input :logo, as: :file ,:input_html => { :class => "form-control" },:placeholder => "",:label=>false %>
<% end %>
<%= f.button :submit, "Agree and Continue",:class=>"btn btn-default signup_button" %>
<% end %>
I have dropdown of gender and its data type is boolean in rails4.
I use below code to display dropdown of gender:
<%= f.select(:gender, {"Female" => false, "Male" => true}, {:selected => (#user.gender?)}) %>
but when i click on update it raise below error:
'false' is not a valid gender
#ashvin you can use radio button for gender as follow.
<%= f.label :gender %><br />
<%= f.label :gender, "Male", :value => "true" %>
<%= f.radio_button :gender, true %>
<%= f.label :gender, "Female", :value => "false" %>
<%= f.radio_button :gender, false %>
Your code is wrong,try with this
<%= f.select(:gender, [['Female',false], ['Male',true]], {:selected => (#user.gender?)}) %>
I am using Rails 4.0.4 and Ruby 2.1.1.
I made few changes in my devise login form after generating migration for username and find the ActiveAdmin is throwing following error.
Showing /Users/MyCom/.rvm/gems/ruby-2.1.1/bundler/gems/active_admin-3136ccb910e8/app/views/active_admin/devise/sessions/new.html.erb where line #8 raised:
wrong number of arguments (6 for 4..5)
Extracted source (around line #8):
<%= active_admin_form_for(resource, :as => resource_name, :url => send(:"#{scope}_session_path"), :html => { :id => "session_new" }) do |f|
f.inputs do
resource.class.authentication_keys.each { |key|
f.input key, :label => t('active_admin.devise.'+key.to_s+'.title'), :input_html => {:autofocus => true}
}
f.input :password, :label => t('active_admin.devise.password.title')
f.input :remember_me, :label => t('active_admin.devise.login.remember_me'), :as => :boolean if devise_mapping.rememberable?
Following is my code in views/devise/sessions/new
<div class="panel-body">
<div class="col-md-6">
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<div class="form-group">
<%= f.label :username %>
<%= f.input_field :username, class: "form-control", :autofocus => true %>
</div>
<div class="form-group">
<%= f.label :password %>
<%= f.password_field :password, class: "form-control" %>
</div>
<div class="form-group">
<div class="checkbox">
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
</div>
</div>
<div class="form-group">
<%= f.submit "Sign in", class: "btn btn-primary" %>
</div>
<% end %>
</div>
</div>
I was able to fix doing the following.
I had to change my config/initializers/simple_form_bootstrap.rb file.
I had added following which I had to take it out.
inputs = %w[
CollectionSelectInput
DateTimeInput
FileInput
GroupedCollectionSelectInput
NumericInput
PasswordInput
RangeInput
StringInput
TextInput
]
inputs.each do |input_type|
superclass = "SimpleForm::Inputs::#{input_type}".constantize
new_class = Class.new(superclass) do
def input_html_classes
super.push('form-control')
end
end
Object.const_set(input_type, new_class)
end
This issue is discussed in details here.
https://github.com/gregbell/active_admin/issues/2703
I have nested attributes in my form and 2 models - Artwork and ArtDescription, which connected has_one/belongs_to but i've got error
ActiveRecord::AssociationTypeMismatch in ArtworksController#create
ArtDescription(#30842620) expected, got
ActionController::Parameters(#9409680)
whats wrong?
Form
<%= form_for :artwork, url: artworks_path do |f| %>
<p>
name:<%= f.text_field :name %></br>
author:<%= f.text_field :author %></br>
date:<%= f.text_field :date %></br>
museum:<%= f.text_field :museum %></br>
place:<%= f.text_field :create_place %></br>
comment:<%= f.text_field :comment %></br>
</p>
<p>
<%= f.fields_for :art_description do |artdesc|%>
type:<%= artdesc.text_field :type %></br>
base:<%= artdesc.text_field :base %></br>
style:<%= artdesc.text_field :style %></br>
genre:<%= artdesc.text_field :genre %></br>
plot:<%= artdesc.text_field :plot %></br>
reference: <%= artdesc.text_field :reference %></br>
format_weight: <%= artdesc.text_field :format_weight%></br>
format_height:<%= artdesc.text_field :format_height %></br>
<% end %>
<%= f.submit ('Ok')%> </p>
<% end %>
Controller ArtworksController
def create
#artwork = Artwork.create(artwork_params)
if #artwork.save
redirect_to artwork_path(#artwork)
else
render 'new'
end
end
Model
class Artwork < ActiveRecord::Base
has_one :art_description
accepts_nested_attributes_for :art_description
end
Strong Parametrs
def artwork_params
params.require(:artwork).permit(:name, :author, :date, :museum, :comment, :create_place, art_description: [ :type, :base, :style, :genre, :plot, :reference, :format_weight, :format_height])
end
Your strong params line should use art_description_attributes, not art_description:
params.require(:artwork).permit(:name, :autor, :date, :museum, :comment, :create_place, art_description_attributes: [ :type, :base, :style, :genre, :plot, :reference, :format_weight, :format_height])