Why doesn't my partial work with slim and Rails 3.2? - ruby-on-rails-3

I'm using Rails 3.2 and instead of ERB, I am using slim.
Here is my form partial:
= simple_form_for #game, :html => { :class => 'form-horizontal' } do |f|
The syntax error I am getting is:
_form.html.slim:1: syntax error, unexpected ')' ... => 'form-horizontal' } do |f|))).to_s));
But I don't know where it expects to put the ')'?
Thanks

The syntax should be:
= form_for([#resource], html: { multipart: true }, remote: true) do |f|
Try substituting your values.
I was not able to find the correct documentation for slim form helper.

Related

rails observe_form and prototype: return '$A($(form).getElementsByTagName('*'))'

I have observe_form in my view:
<%= observe_form 'new_lead', :url => { :action => 'update_price' }, :frequency => 0.1 %>
, _update_price.rjs partial and this method in controller:
def update_price
unless request.xhr?
redirect_to :controller => 'index'
else
set_price_group
render :partial => "update_price",
:locals => { :services => params[:service],
:spectr => params[:spectr] }
end
end
I'm upgrading rails_2 app to rails_3.
On rails_2 it's no errors, but when I upgrade project to rails3
I have javascript error in 3484 line of prototype.js:
"$(...).getElementsByTagName is not a function ".
getElements: function(form) {
return $A($(form).getElementsByTagName('*')).inject([],
function(elements, child) {
if (Form.Element.Serializers[child.tagName.toLowerCase()])
elements.push(Element.extend(child));
return elements;
}
);},
And 'update_price' does not calling periodically.
I don't know is it problem related to rails upgrading or just problem with JS :(
How can I fix this problem?
Rails 3.1 uses jQuery instead of Prototypejs. You can get back the prototype functionality by using something like https://github.com/rails/prototype-rails
Related How to swap jquery for prototype in Rails 3.1
Than if somebody have an error:
TypeError: document.on is not a function
Changing prototype.js 1.6.x to 1.7 will solve it ;)

Specifying :class of embedded ruby form

If I would like to assign a class to my embedded ruby form, like so?:
<%= form_for(User.new) do |f|, :class => "form-horizontal" %>
How could I go about doing it? I keep getting a syntax error.
Thanks!
from http://apidock.com/rails/ActionView/Helpers/FormHelper/form_for
form_for(record, options = {}, &proc)
meaning:
<%= form_for(User.new, { :class => 'form-horizontal' }) do |f| %>

Rails error: can't convert Symbol into Integer

Using the google maps API and rails 3.2.1 I have page allowing to move the business marker on a map to correct it's position. The business model has latitude and longitude (amongst others). The relevant part is:
<%= form_for :business, :url => { :action => "updatemap" }, :id => 'updatebutton' do |f| %>
<%= f.hidden_field :latitude %>
<%= f.hidden_field :longitude %>
<br />
<%= f.submit "Save" %>
<% end %>
The method updatemap is:
def updatemap
#business = Business.find(params[:id])
#business.latitude = params([:business][:latitude])
#business.longitude = params([:business][:longitude])
if #business.save!
redirect_to business_path(#business), :flash => { :success => "The business was updated!" }
else
render 'changemap', :flash => { :error => "An error occured." }
end
end
Running the debugger, params([:business][:latitude]) and params([:business][:longitude]) give the correct value of the new map coordinates (e.g. "45.273739" for latitude). But there is an error:
TypeError in BusinessesController#updatemap
can't convert Symbol into Integer
(the line of the error is the #business.latitude = params([:business][:latitude]) line)
I also tried with
...
if #business.update_attributes(params[:business])
...
but the error is the same. What causes the error and how can I correct it?
You are writing params([:business][:latitude]) rather than params[:business][:latitude]. That means that [:business] is actually a method call on self, rather than params. Presumably the class which this code is part of has a [] method, but it expects an integer rather than :business.

Rendering the Devise edit Password Form

I'm trying to render the Devise edit password form within another view because I don't want to duplicate the edit pw logic.
I've tried the following (after generating the Devise views):
<%= render 'devise/passwords/edit' %>
<%= render 'devise/passwords/form' %>
And a number of other variations on render that all seem to give me the same error:
"ActionView::MissingTemplate in foo#foo
Missing partial devise/passwords/edit..."
This variation:
<%= render :file => 'devise/passwords/edit.html.erb' %>
Gave me some hope but the following error:
"undefined local variable or method `resource' for #<#:0x47ef0e0>"
around this line:
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
That makes me think I'm close (as that is code from the form that I want) but shouldn't that template be using the correct logic from the hidden Devise controller? Or do I need to do something in the routes file to get this to work?
Am I way off?
Try this:
<%= render :template => 'devise/passwords/edit',
:locals => {
:resource => my_user_model_variable,
:resource_name => my_user_model_name } %>
Where:
my_user_model_variable could be current_user
my_user_model_name could be "User"

HAML form_tag problems with dropdown menue

%h2 Your "followers":
- form_tag twitter_path do |f|
= f.select{:name => "dropdown"}
- for follower in #followers
%option{:value => follower['id']}= h follower['name']
= f.submit_tag "Who leaves comments?"
How do you properly format this HAML? Its returning a Syntax Error.
You're using HAML syntaxe inside Ruby code here:
= f.select{:name => "dropdown"}
The brace { is interpreted as the begining of a Ruby block (like in array.map { ... }), because everything after the = or - prefix in HAML is evaluated as Ruby code.
Also, you're using the form_for syntax while using the form_tag method (see this question).
The form_tag method doesn't provide a form object f.
You should use the select_tag method from FormTagHelper instead, along with a FormOptionsHelper method:
- form_tag twitter_path do
= select_tag "dropdown", options_from_collection_for_select(#followers, "id", "name")
= submit_tag "Who leaves comments?"