Strange issue using HAML - ruby-on-rails

When I copied _form.haml partial to _edit_form.haml partial and replaced "_form", with "_edit_form" in my edit.haml I got strange error (maybe it is not strange, I just cant understand the reason).
wrong number of arguments (0 for 1)
Extracted source (around line #1):
1: = form.label :email
2: %br
3: = form.text_field :email
4: %br
.../app/views/users/_edit_form.haml:1:in `form'
.../app/views/users/_edit_form.haml:1:in `_run_haml_app47views47users47_edit_form46haml_locals_edit_form_object'
.../app/views/users/edit.haml:5:in `_run_haml_app47views47users47edit46haml'
.../app/views/users/edit.haml:3:in `_run_haml_app47views47users47edit46haml'
Here is edit.haml:
%h1 Edit My Account
- form_for #user, :url => account_path do |f|
= f.error_messages
= render :partial => "edit_form", :object => f
= f.submit "Update"
%br
= link_to "My Profile", account_path
...and edit_form.haml
= form.label :email
%br
= form.text_field :email
%br
%br
= form.label :old_password, "Old password"
%br
= form.password_field :old_password
%br
%br
= form.label :password, "Change password"
%br
= form.password_field :password
%br
%br
= form.label :password_confirmation
%br
= form.password_field :password_confirmation
%br
I can't understand where is the problem. Because it worked nicely with _form.haml
diff _form.haml _edit_form.haml
1c1
< = form.label :login
---
> = form.label :email
3c3
< = form.text_field :login
---
> = form.text_field :email
6c6
< = form.label :email
---
> = form.label :old_password, "Old password"
8c8
< = form.text_field :email
---
> = form.password_field :old_password
11c11
< = form.label :password, form.object.new_record? ? nil : "Change password"
---
> = form.label :password, "Change password"

The :object is implicitly exposed in the partial as the name of the partial. Change form to edit_form in _edit_form.haml and it should work.

Related

cocoon rails, how to get atached file name

Im using cocoon to attach files. I need to be able to remove file when editing a question. Im stuck on getting the exact file name to remove when rendering edit
div.edit_question
=form_for #question, remote: true do |f|
= f.label :title, class: 'label_hidden'
= f.text_field :title
br
= f.label :body, class: 'label_hidden'
= f.text_area :body
br
= f.fields_for :attachments do |f|
.nested-fields
= link_to_remove_association "remove #{ NAME HERE }", f
br
= f.submit 'Update'
Case is closed ))
=form_for #question, remote: true do |f|
= f.label :title, class: 'label_hidden'
= f.text_field :title
br
= f.label :body, class: 'label_hidden'
= f.text_area :body
br
- #question.attachments.each do |att|
= f.fields_for att do |f|
.nested-fields
= link_to_remove_association "remove #{ att.file.filename }", f
br
= f.submit 'Update'

how to show simple_form vertically

= simple_form_for #session, :as => 'session', :url => session_path do |form|
%form
.form-group
.form
= form.input :email
.form
= form.input :password
.form-actions
%button.btn.btn-primary{type: "submit"} Log in
above sample generates the following horizontal view, where input fields are to the right of labels
*Email [input]
*Password [input]
Is it possible to show them vertically on top of each other, so labels are above input fields? How can it be achieved?
*Email
[input]
*Password
[input]
= simple_form_for #session, :as => 'session', :url => session_path do |form|
%form
.form-group
.form
%div
= form.label :email
= form.email_field :email
%div
= form.label :password
= form.password_field :password
According to the github page:
https://github.com/plataformatec/simple_form
<%= f.input :username, label: 'Your username please' %>
Will make the label a block element, instead of inline_label.
Or you can specify the label and the input field seperately:
<%= f.label :username %>
<br/>
<%= f.input_field :username %>
Try this one:
%label Email*
%div
= form.input :email
%label Password*
%div
= form.input :password

Haml form that is expecting $end?

Hi I'm really new to Rails, and Haml of course and I've been trying to figure this out for couple days already.
when rendering pages with this partial I get error:
app/views/todos/_form.html.haml:19: syntax error,unexpected keyword_end, expecting $end
(Please excuse my indentation errors, I didn't have an option to copy and paste)
_form.html.haml contents:
1 = form_tag :todo do |f|
2 %br
3 = f.label :done
4 = f.check_box :done
5 = f.label :title
6 = f.text_field :title
7 %br
8 = f.label :urgent
9 = f.check_box :urgent
10 %br
11 = f.label :important
12 = f.check_box :important
13 %br
14 = f.label :description
15 %br
16 = f.text_area :description
17 %br
18 = f.submit "Save"
19
In HAML, you cannot have any direct sub elements to a = unless it's a block. As an = is ruby code and not part of the html template as such.
If you want sub elements to a = thay will need to passed to a ruby block like the = form_tag do |f| does.
So it's your check_box's that are causing this error.
In this example I would move both the form helpers to a single line like this:
= form_tag :todo do |f|
%br
= f.label :done, f.check_box(:done)
= f.label :title
= f.text_field :title
%br
= f.label :urgent, f.check_box(:urgent)
%br
= f.label :important, f.check_box(:important)
%br
= f.label :description
= f.text_area :description
%br
= f.submit "Save"
You could also tell the label helper to accept a block by adding do at the end of the method call:
= form_tag :todo do |f|
%br
= f.label :done do
= f.check_box(:done)
...
Or even use an haml element instead of the rails form helper to make the label:
= form_tag :todo do |f|
%br
%label{:for => 'done'}
= f.check_box :done
...
Your indentations and nesting aren't consistent. I usually go with 2 spaces.
Try:
= form_tag :todo do |f|
%br
= f.label :done
= f.check_box :done
= f.label :title
= f.text_field :title
%br
= f.label :urgent
= f.check_box :urgent
%br
= f.label :important
= f.check_box :important
%br
= f.label :description
%br
= f.text_area :description
%br
= f.submit "Save"
This converts nicely to erb:
<%= form_tag :todo do |f| %>
<br>
<%= f.label :done %>
<%= f.check_box :done %>
<%= f.label :title %>
<%= f.text_field :title %>
</br>
<br>
<%= f.label :urgent %>
<%= f.check_box :urgent %>
</br>
<br>
<%= f.label :important %>
<%= f.check_box :important %>
</br>
<br>
<%= f.label :description %>
</br>
<% end %>

Unable to save data add to the model created with Devise (name model : user )

I use currency with ruby rails 4, I add fields in my user table I created with currency and the concern is when I want to change my email it works but if I want to update the other fields nothing happens so I do not know what 'would forget.
Here the form of currency or I add the fields.
%h2
Edit #{resource_name.to_s.humanize}
= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f|
= devise_error_messages!
%div
= f.label :email
%br
= f.email_field :email, :value =>"#{current_user.email}"
%div
= f.label 'Mot de passe'
%i (Pour valider votre profil)
%br
= f.password_field :current_password
%div
= f.label 'Nom'
%br
= f.text_field :username, :value=>"#{current_user.username}"
%div
= f.label 'Prenom'
%br
= f.text_field :firstname, :value=>"#{current_user.firstname}"
%div
= f.label 'Adresse'
%br
= f.text_field :adress, :value=>"#{current_user.adress}"
%div
= f.label 'Code postal'
%br
= f.text_field :cp, :value=>"#{current_user.cp}"
%div
= f.label 'Ville'
%br
= f.text_field :city, :value=>"#{current_user.city}"
%div= f.submit "Mise à jour du profil"
To update the custom fields that you added to Devise model, you will have to permit them explicitly:
Add the following code in your ApplicationController
class ApplicationController < ActionController::Base
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
## Permit the custom fields below which you would like to update, I have shown a few examples
devise_parameter_sanitizer.for(:account_update) << :currency << :username << :firstname
end
end

Error 'block_is_haml?' Haml = f.label in Ruby 1.9

app/views/users/_form.html.haml, line 10
= form_for #user do |f|
- if #user.errors.any?
#error_explanation
%h2= "#{pluralize(#user.errors.count, "error")} prohibido que este usuario se guarde:"
%ul
- #user.errors.full_messages.each do |msg|
%li= msg
.field
= f.label 'Usuario'
= f.text_field :username
.field
= f.label :email
= f.text_field :email
.field
= f.label 'Teléfono'
= f.phone_field :phone
.field
= f.label 'Contraseña'
= f.password_field :password
.field
= f.label 'Reingresar Contraseña'
= f.password_field :password_confirmation
.control-group
//= f.label 'Permisos'
%ul.unstyled
- for role in Role.find(:all)
%li
= check_box_tag "user[role_ids][]", role.name, #user.roles.include?(role)
= role.name
%br
.actions
= f.submit 'Guardar',:class => 'btn btn-primary'
Error seems to be in the = f.label I've deleted all the = f.label and no errors were thrown, also changed = f.label 'Usuario' for = f.label :username with no luck.
Error Message:
ArgumentError in Users#new
Showing C:/Sites/AutosCostaRica/app/views/users/_form.html.haml where line #10 raised:
syntax error in "<reader>", line 3, column 18:
next_label: >>
^
Update:
I just found out that it works perfect on Ruby 1.8, but I waned to be 1.9.
Any ideas?

Resources