In the part of code below I am still getting this error:
syntax error, unexpected keyword_ensure, expecting $end):
17: %input.btn.btn-primary{:name => "commit", :type => "submit", :value => "Set As Profile Picture"}/
Code:
#settings_photos_window.wide_width.modal.fade
= form_tag '/photos/set_avatar', :method => 'post' do
.modal-header
%a.close{"data-dismiss" => "modal"} ×
%h3 Choose Your Profile Picture
#choose_profile_pic.modal-body
= hidden_field_tag 'photo[avatar]', ((#cur_avatar) ? #cur_avatar.id : '')
- #settings_photos.each_slice(2) do |slice|
.row{:style => "text-align: left;"}
- slice.each do |photo|
- (photo.avatar == 1) ? (bg_color = 'background: #28AD4B;') : (bg_color = 'background: #fff;')
.span5.choose_picture{:style => "cursor: pointer; margin-right: 40px;"}
%div
= image_tag(photo.photo.url(:thumb), :class => 'thumbnail', :id => photo.id, :style => bg_color)
%br/
.modal-footer
%input.btn.btn-primary{:name => "commit", :type => "submit", :value => "Set As Profile Picture"}/
What could be wrong, or... doesn't exist any debugger for HAML?
Thanks
I think its probably the parentheses around the tenary statements. Its just a guess, but the rest of it seems perfectly acceptable to me.
Related
#social_list
= form_tag notes_path, class: 'form clearfix', id: 'add_post_form',multipart: true, remote: true
.control-group
= text_area_tag "comment[text]", '', :placeholder => 'Post to the community', :cols => nil, :rows => nil, :class => 'mention expand-without-submit'
= file_field_tag "picture", id:'image_upload', accept: 'image/png,image/gif,image/jpeg'
= submit_tag "Post your message", class: 'btn btn-success btn-mini'
= form_tag images_path
= submit_tag 'asad'
= render "dashboards/activity_stream_filter"
I want to add second form but it is giving me this error.
syntax error, unexpected keyword_ensure, expecting $end
I guess some scoping issue is messed up or is the possible to have multiples form in single page ?
The form_tag method takes a block for the form contents. In your first form you have’t provided a block at all since nothing is indented below it. In the second case there is content indented below, but you haven’t included the do. This second case is causing the syntax error.
What I think you want is
#social_list
- # note 'do' added to this line:
= form_tag notes_path, class: 'form clearfix', id: 'add_post_form',multipart: true, remote: true do
- # this section indented:
.control-group
= text_area_tag "comment[text]", '', :placeholder => 'Post to the community', :cols => nil, :rows => nil, :class => 'mention expand-without-submit'
= file_field_tag "picture", id:'image_upload', accept: 'image/png,image/gif,image/jpeg'
= submit_tag "Post your message", class: 'btn btn-success btn-mini'
- # 'do'added to next line
= form_tag images_path do
= submit_tag 'asad'
= render "dashboards/activity_stream_filter"
I may be old school,and I've been through many div/span attempts and swore off tables at one time, but there are just some good uses for tables, one of them, imho, is a form. I prefer to shade my label fields with a different background color. I've tried may ways, but if the input (actually either) side overflows the width, it will mess up the label background. I'd look at another attempt, but I really prefer a table approach.
In 2.x I set my configuration to:
config.wrappers :tag => :tr, :class => :input,
:hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
b.use :label, :wrap_with => {:tag => :td, :class => :label}
b.use :input, :wrap_with => {:tag => :td, :class => :input}
b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
b.use :error, :wrap_with => { :tag => :caption, :class => :error }
Works great!, except for errors. I first had it as a span and it went to the top of the table. I then set it to caption and, at least in Safari, it ends tbody and puts in the caption and starts another tbody - but it screws up the table flow.
Is there a way I can force the error to be in the input wrapper? Or any other approach? I'd even accept (and maybe this is what I should do) putting the error in the main message like the scaffold approach. Didn't think about that until I started to write this, but I guess I could not use simple forms error stuff and go back to the scaffold approach.
At least I think you can do that. For instance, I didn't know (and could not find in documentation - but I didn't look real hard!) that you could use regular form_for input (e.g., f.text_field) mixed with f.input. Great for things like putting City, St, Zip on one row.
I guess I should answer my own question. I ended up not using Simple Forms error notification and went back to the scaffold method.
I configured my wrappers as follows:
config.wrappers :tag => :tr, :class => :input,
:hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
b.use :label, :wrap_with => {:tag => :td, :class => :label}
b.use :input, :wrap_with => {:tag => :td, :class => :input}
Wrote a helper method for errors:
def show_form_errors(instance)
if instance.errors.any?
errors = content_tag(:h2, pluralize(instance.errors.count, "error") +"prohibited this project from being saved:")
list = content_tag :ul do
e = ""
instance.errors.full_messages.each do |msg|
e <<"<li>#{msg}</li>"
end
e.html_safe
end
return content_tag(:div, (errors + list),:id => "error_explanation").html_safe
end
end
# instead of
# = f.error_notification
# I used
# = show_form_errors(#event)
Had to tweak the CSS for error_explanation because of how I had borders defined on my table rows (just border-bottom) and add !important to wrap the tr with a red border:
.field_with_errors {
padding: 2px;
border:solid 3px red!important;
background-color:pink;
}
Works fine and I am content with this method.
I first installed devise and altered it so I can login with username instead of email.
After that I entered the Activeadmin gem into my gem file.
After that I did a bundle install and rake active_admin:install.
But after trying to log into the backend /admin/login I see this error message :
undefined method `username' for #<AdminUser:0x00000004bb2e58>
On this code :
Extracted source (around line #7):
4: <% scope = Devise::Mapping.find_scope!(resource_name) %>
5: <%= active_admin_form_for(resource, :as => resource_name, :url => send(:"#{scope}_session_path"), :html => { :id => "session_new" }) do |f|
6: f.inputs do
7: resource.class.authentication_keys.each { |key| f.input key, :input_html => {:autofocus => true}}
8: f.input :password
9: f.input :remember_me, :label => t('active_admin.devise.login.remember_me'), :as => :boolean, :if => false #devise_mapping.rememberable? }
10: end
Anyone a idea how to solve this ?
If you need more info just ask.
Roelof
edit : I thought I could solve this by doing this: http://blog.blazingcloud.net/2012/07/29/activeadmin-with-existing-devise-authentication/
But now all the login are failed ( 401) where they without activeadmin they were successfull
I was having the same error and I solved it adding this to my AdminUser model
def login=(login)
#login = login
end
def login
#login || self.email
end
def self.find_for_database_authentication(warden_conditions)
conditions = warden_conditions.dup
login = conditions.delete(:login)
where(conditions).where(["lower(email) = :value", { :value => login.strip.downcase }]).first
end
I have a edit form in Active Admin. I need some field as read only.
My current edit page is like
I need the page look like this
How can this be done. My code for the edit form page is like
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs "Users" do
f.input :device, :label => 'Device', :as => :select, :collection => DEVICE, :include_blank => false
f.input :current_address, :label => 'Current Address', :as => :string
end
end
Please help.
As Alex said, set to disabled. You could then use css to get the visual you wanted, if you can live with the semantics of that.
The syntax was slightly different for me to get this to work.
in your admin form:
f.input :finish_position, input_html: { disabled: true }
in your CSS active_admin.css
input[disabled="disabled"],
input[disabled] {
background-color: #F4F4F4;
border: 0px solid #F4F4F4 !important;
}
For a cleaner form definition within your ActiveAdmin.register{} block you may as well want to define a "readonly" input type to be used within active admin using formtastic:
Form block syntax is for activeadmin version 1.0.0.pre at 0becbef0918a.
# app/admin/inputs/readonly_input.rb
class ReadonlyInput < Formtastic::Inputs::StringInput
def to_html
input_wrapping do
label_html <<
template.content_tag('div', #object.send(method))
end
end
end
# app/admin/your_model.rb
ActiveAdmin.register YourModel do
# ...
form do |f|
# ...
input :current_address, as: :readonly
# ...
end
end
I was facing the same issue and tried using :disabled but it did not solve my problem as I wanted field value to be included in params object while sending it to the server. When you mark a form input as :input_html => {:disabled => true} , it does not include this field value in params.
So, instead I used :input_html => {:readonly => true} which solved both of my problems:
Does not allow user to edit
Includes the value in params
I hope this will help.
How about this?
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs "Users" do
f.input :device, :label => 'Device', :as => :select, :collection => DEVICE, :include_blank => false
f.li do
f.label :current_address
f.span f.object.current_address
end
end
end
Try to add , :disabled => true for address input field.
The trick is to use "object". Here is how you should code it:
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs "Users" do
f.input :device, :label => 'Device', :as => :select, :collection => DEVICE, :include_blank => false
f.label :current_address, f.object.current_address
end
end
I have a partial _new_user_form.html.erb
<%= form_for(#user, :remote => true, :html => {:id => 'new_user_form'}) do |f|%>
<strong><%= :form_text %></strong>
<%= f.text_field :email, :placeholder => get_placeholder_text(#board), :size => "30" %>
<%= hidden_field_tag :role, role %>
<%=f.submit "SAVE", :class => "button-small" %>
<% end %>
In the show.rb I want to use it and pass in some partial variables as follows:
<%= render 'users/new_user_form', :locals=> {:role => "Celebrant" } %>
However I get this error:
undefined local variable or method `role' for #<#<Class:0x00000103d5e8b0>:0x00000103d5b930>
I read the documents about passing in locals and this seems correct. What am I doing wrong?
You're combining the short and long forms. Either of these are correct (identical):
render 'my_partial', :foo => 'bar'
render :partial => 'my_partial', :locals => { :foo => 'bar' }
I think you're calling render incorrectly. From the fine manual:
If no options hash is passed or :update specified, the default is to render a partial and use the second parameter as the locals hash.
So you end up going down this branch in the source:
view_renderer.render_partial(self, :partial => options, :locals => locals)
and that makes your call the same as this:
render :partial => 'users/new_user_form', :locals => { :locals => { :role => 'Celebrant } }
Note the extra level of nesting for :locals. Try this:
render 'users/new_user_form', { :role => 'Celebrant' }
I'm looking at (and using) 3.1 so your version might be a little different.