Sessions#New Wrong Number of Arguments Error after upgrading to Rails4 - ruby

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.

Related

upload image and files padrino

i want to put index image to my blog's posts
and have an upload form in 'new post 'in admin's panel
the form is written like this :
- error = #post.errors.include?(:file)
%fieldset.control-group{:class => error ? 'has-error' : ''}
=f.label :file, :class => 'control-label'
.controls
=f.file_field :file ,:name => 'file'
- error = #post.errors.include?(:title)
%fieldset.control-group{:class => error ? 'has-error' : ''}
=f.label :title, :class => 'control-label'
.controls
=f.text_field :title, :class => 'form-control input-large input-with-feedback', :autofocus => true
%span.help-inline=error ? f.error_message_on(:title, :class => 'text-error') : pat(:example)
- error = #post.errors.include?(:body)
%fieldset.control-group{:class => error ? 'has-error' : ''}
=f.label :body, :class => 'control-label'
.controls
~f.text_area :body, :class => 'form-control input-large input-with-feedback'
%span.help-inline=error ? f.error_message_on(:body, :class => 'text-error') : pat(:example)
.form-actions
=f.submit pat(:save), :class => 'btn btn-primary'
=f.submit pat(:save_and_continue), :class => 'btn btn-info', :name => 'save_and_continue'
=link_to pat(:cancel), url(:posts, :index), :class => 'btn btn-default'
but i don't know what i must do in functions to save file .
An easy-to-follow guide (assuming you are using activerecord. otherwise change 1st line on example).
Add carrierwave to your Gemfile, and execute bundle install.
Generate a migration: padrino g AddImageToPosts image:string and execute it.
Add mount_uploader :image, Uploader to your Post model.
Inside your lib folder create a file, named uploader.rb (or whatever, but then do not forget to change Uploader on 3rd step.)
Add lines from 7 to 83 to uploader.rb (do not forget uncomment lines, and fix them so they to match your needs).
Browse admin, click browse button for file upload - select a file from filesystem - you are done.
example (step 3)
require 'carrierwave/orm/activerecord'
class Post < ActiveRecord::Base
belongs_to :category
mount_uploader :image, Uploader
...
end

Devise user sign up form with business model

I'm trying to create a user sign up form with Devise that will also allow for the creation of a new business associated with that user.
I have a business model setup and can't seem to save the business information to the database. Below is my code, I'm fairly new to rails so I apologize if I'm asking a question with an obvious answer.
new.html.erb (user)
<div class="content">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h1>Sign Up</h1>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="form-group">
<label>Name</label>
<%= f.text_field :username, :autofocus => true, :class => "form-control", :placeholder => "Full Name" %>
</div>
<div class="form-group">
<%= f.label :email %>
<%= f.text_field :email, :class => "form-control", :placeholder => "Email" %>
</div>
<div class="form-group">
<%= f.label :password %>
<%= f.password_field :password, :class => "form-control", :placeholder => "Password" %>
<p class="help-block">Passwords must be a minimum of 8 characters.</p>
</div>
<div class="form-group">
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation, :class => "form-control", :placeholder => "Retype Password" %>
</div>
<!-- Business Infomation -->
<h2>Business Information</h2>
<%= f.fields_for :business do |b| %>
<div class="form-group">
<%= b.label :name %>
<%= b.text_field :name, :class => "form-control", :placeholder => "Business Name" %>
</div>
<div class="form-group">
<%= b.label :address %>
<%= b.text_field :address, :class => "form-control", :placeholder => "Address" %>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<%= b.label :city %>
<%= b.text_field :city, :class => "form-control", :placeholder => "City" %>
</div>
</div>
<div class="col-sm-2">
<div class="form-group">
<%= b.label :state %>
<%= b.text_field :state, :class => "form-control", :placeholder => "State" %>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<%= b.label :zip %>
<%= b.text_field :zip, :class => "form-control", :placeholder => "ZIP" %>
</div>
</div>
</div>
<div class="form-group">
<%= b.label :country %>
<%= b.text_field :country, :class => "form-control", :placeholder => "Country" %>
</div>
<% end %>
<div class="well">
<%= f.submit "Sign Up", :class => "btn btn-primary" %>
</div>
<% end %>
</div>
</div>
user.rb
class User
include Mongoid::Document
include Mongoid::Paperclip
rolify
include Mongoid::Timestamps
#embeds_many :businesses, :class_name => "Business"
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :role_ids, :as => :admin
attr_accessible :username, :email, :password, :password_confirmation, :remember_me, :business_ids,
:reset_password_sent_at, :reset_password_within, :address, :city, :state, :zip, :country, :phone, :business_attributes
has_one :businesses
accepts_nested_attributes_for :businesses
validates_format_of :email, :with=>email_regexp, :allow_blank => true, :message=> "Justin"
#intercom
attr_accessor :company_name
attr_accessible :company_name
## Database authenticatable
field :email, :type => String, :default => ""
field :encrypted_password, :type => String, :default => ""
## Recoverable
field :reset_password_token, :type => String
#field :reset_password_sent_at, :type => Time
field :reset_password_sent_at, :type => Time
## Rememberable
field :remember_created_at, :type => Time
#field :remember_created_at, :type => String
## Trackable
field :username, :type => String
field :sign_in_count, :type => Integer, :default => 0
#field :current_sign_in_at, :type => Time
#field :last_sign_in_at, :type => Time
field :current_sign_in_at, :type => Time
field :last_sign_in_at, :type => Time
field :current_sign_in_ip, :type => String
field :last_sign_in_ip, :type => String
field :first_name, :type => String
field :last_name, :type => String
#field :business_ids, :type => Array
field :address, :type => String
field :city, :type => String
field :state, :type => String
field :zip, :type => String
field :country, :type => String
field :phone, :type => String
# User Avatar
attr_accessible :avatar
has_mongoid_attached_file :avatar,
:styles => { :full => ["512x512>", :jpg], :medium => ["256x256>", :jpg] },
:convert_options => {:medium => "-background black -gravity center -extent 256x256"},
:default_url => "/assets/avatar-blank.png"
validates_attachment_size :avatar, :less_than => 5.megabytes
validates_attachment_content_type :avatar, :content_type => ['image/jpeg', 'image/jpg', 'image/png', 'image/gif']
## Confirmable
# field :confirmation_token, :type => String
# field :confirmed_at, :type => Time
# field :confirmation_sent_at, :type => Time
# field :unconfirmed_email, :type => String # Only if using reconfirmable
## Lockable
# field :failed_attempts, :type => Integer, :default => 0 # Only if lock strategy is :failed_attempts
# field :unlock_token, :type => String # Only if unlock strategy is :email or :both
# field :locked_at, :type => Time
## Token authenticatable
# field :authentication_token, :type => String
after_create :create_business
def create_business
Business.create(business_id: self.id)
end
def assign_default_role(b)
# assign a default role if no role is assigned
# IF, invite token make user an editor for business
# ELSE, make the user owner of the business
self.add_role "owner", b
end
#Returns a businesses for a user. The return type is an array of Business models.
def businesses
Business.find(get_business_ids)
end
#returns the user business_ids (Array of Strings)
def get_business_ids
Business.find_roles(nil, self).map{|b| b.resource_id.to_s}.to_a
end
end
Try override Devise's registration controller:
# app/controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
def create
# save business here
end
end
And then tell devise to use customized controller:
# app/config/routes.rb
devise_for :users, :controllers => {:registrations => "registrations"}

how to create a submit button in a modal?

I have created a normal
= simple_form_for #nacform, :html => { :multipart => true } do |f|
= f.error_notification
.row
.span12
%h4 Form Details
%hr
.row
.span3
.field
= f.input :Title
.field
= f.input :Description
.field
= f.label :asset, "File"
= f.file_field :asset
.form-actions
= link_to 'Back', nacforms_path, :class => 'btn btn-small btn-primary'
%a#modal_btn.btn.btn-success.btn-small{:href => "#modal"} Continue
and the modal
#modal.modal.hide
.about
.modal-header
%button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"} ×
%h2 Forms
= simple_form_for #nacform, :html => { :multipart => true } do |f|
= f.button :submit, "Upload Form", :class => 'btn btn-success'
:javascript
$("#modal_btn").click(function(){
$('#modal').modal();
});
the submit button for the form is on the modal, but when i click on that submit button nothing happens, Am I doing it wrong ?
In order for things to appear using jQuery show method or something derived from it, you generally specify an inline style that's easy to override:
#modal.modal{ :style => 'display:none' }
Having a .hide CSS class may be what's causing it to stay hidden.

can't convert nil into String

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.

Haml "Illegal Nesting" problem; how to place multiple code elements in the same tag?

- #subjects.each do |s|
%tr
%td= s.position
%td= s.name
%td= s.visible ? "Yes" : "No"
%td= s.pages.size
%td= link_to("Show", {:action => "show", :id => s.id}, :class => "action show")
= link_to("Edit", {:action => "edit", :id => s.id}, :class => "action edit")
= link_to("Delete", {:action => "delete", :id => s.id}, :class => "action delete")
error_msg:
Illegal nesting: content can't be both given on the same line as %td and nested within it.
I want those three links--show, edit, and delete--in the same td; how can I do it?
You just need to change this:
%td= link_to("Show", {:action => "show", :id => s.id}, :class => "action show")
= link_to("Edit", {:action => "edit", :id => s.id}, :class => "action edit")
= link_to("Delete", {:action => "delete", :id => s.id}, :class => "action delete")
to this:
%td
= link_to("Show", {:action => "show", :id => s.id}, :class => "action show")
= link_to("Edit", {:action => "edit", :id => s.id}, :class => "action edit")
= link_to("Delete", {:action => "delete", :id => s.id}, :class => "action delete")
You should also indent the tds from the tr.
FYI - I ran into this issue too but the culprit was a trailing space after my <td>, which is content for HAML.

Resources