Any idea on what could be wrong in this form?
Error:
vehicleTrack.html.erb:141: syntax error, unexpected keyword_do_block, expecting => ... params[:rangefrom_string]} do |f| #output_buffer.safe_appe... ... ^
This is my view:
<%= simple_form_for '', url: convertTrackToArea_path, :method => :post,
{ :controller => "vehicles",
:action => "convertTrackToArea",
:search => params[:search],
:rangefrom_string => params[:rangefrom_string]} do |f| %>
<%= f.input :areano, :label => 'Areano' %>
<%= f.button :submit, value: "Crear",:name => nil%>
<% end %>
I have not used simple_form so my guess is you are passing the last last argument incorrectly and it wont take a hash as argument and it detects the argument as key and searching for a value so throws error that => is missing, which is used to identify value in hash. So you can do something like this I suppose:
<%= simple_form_for '',
:url => url_for(:action => 'convertTrackToArea', :controller => 'vehicles',:search => params[:search],
:rangefrom_string => params[:rangefrom_string]),
:method => 'post' do |f| %>
since you are specifying controller and action you dont need to mention convertTrackToArea_path . If that route is already setup, you can just use that like in your posted question and remove controller and action name like:
<%= simple_form_for '', :url => convertTrackToArea_path(:search => params[:search],:rangefrom_string => params[:rangefrom_string]),:method => 'post' do |f| %>
Related
I have this form in a view in my project. I need to pass the task_id to a certain controller, but the log does not seem to be receiving the parameters. I don't know what the problem is.
<%= form_for :taskid, :url => {:action=>"index", :controller=>"statistics"}, :html => {:class => "nifty_form", :method => "GET"} do |f| %>
<%f.hidden_field :task_id, :value => task.id%>
<td><%= f.submit "اختر مهمة لاظهار احصائياتها منفرده"%></td>
<% end %>
You are missing on = after <%. The equal sign is needed whenever you want to the result appears on the HTML, so it is used with the field tags methods or render, for instance. You should not use the equal when using a if, for example, because this is not what you want to print (well, it can be, but most likely it isn't)
<%= form_for :taskid, :url => {:action=>"index", :controller=>"statistics"}, :html => {:class => "nifty_form", :method => "GET"} do |f| %>
<%= f.hidden_field :task_id, :value => task.id%>
<td><%= f.submit "اختر مهمة لاظهار احصائياتها منفرده"%></td>
<% end %>
However, as #AntonGrigoriev pointed out, you should use a object if you have, like this
<%= form_for #task, :url => {:action=>"index", :controller=>"statistics"}, :html => {:class => "nifty_form", :method => "GET"} do |f| %>
or you can simply use the hidden_field_tag
<%= hidden_field_tag :task_id, task.id %>
Hi please test with following code to send hidden value in rails, I have tried and worked for one of my application :
hidden_field_tag(name, value = nil, options = {}) public
eg:
<%= hidden_field_tag(:field_name,value=#offer_status)%>
I have the following line of haml:
=form_tag :action => 'create', :controller => 'comments', :class => 'comment_form' do
But the html that gets output is:
<form accept-charset="UTF-8" action="/comments?class=comment_form" method="post"></form>
I want to set the class. How do I do this?
<-- Update -->
With this:
=form_tag ({ :action => 'create', :controller => 'comments' }, { :class => 'comment_form' }) do
I get this error:
syntax error, unexpected ',', expecting ')'
...', :controller => 'comments' }, { :class => 'comment_form' }...
<-- Second Update -->
The problem above is the space between 'form_tag' and '(' #woahdae's answer is correct
form_tag takes 2 options hashes, the first being passed to url_for, the second being passed to the form builder.
So, you have to do it like:
= form_tag({:action => 'create',...}, {:class => 'comment_form'}) do
otherwise Rails thinks all the key/value pairs are for url_for, which will append any keys it doesn't understand as query parameters.
This works for me:
form_tag named_route, :method => :put, :class => 'disable_on_submit'
With Rails 3.0.15
On Rails 5, you can do the following:
<%= form_tag(your_named_path, {class: 'form-inline'}) do %>
<% end %>
You can do follow as:
form_tag your_path, method: :get, id: "your_id", class: "your_class" do
end
In case you found this question and actually wanted to solve class naming for a form_for:
<%= form_for #task, html: {:class => "custom_class"} do |f| %>
Like in my first question from yesterday, I'm still doing that tutorial.
I've encountered another issue with the Rails 2 / Rails 3 routing differences.
So my question is: How do you "translate" this:
<%= form_remote_tag(:controller => "posts", :action => "create") do %>
to Rails 3 routing?
Edit: This is the error code I get :
Showing C:/Users/Lunasea/Web-Site/Standart/app/views/posts/_message_form.html.erb where line #5 raised:
C:/Users/Lunasea/Web-Site/Standart/app/views/posts/_message_form.html.erb:5: syntax error, unexpected tASSOC, expecting '}'
...pend= form_tag {:controller => "posts", :action => "create"...
C:/Users/Lunasea/Web-Site/Standart/app/views/posts/_message_form.html.erb:5: syntax error, unexpected ',', expecting '}'
...rm_tag {:controller => "posts", :action => "create"}, :remot...
C:/Users/Lunasea/Web-Site/Standart/app/views/posts/_message_form.html.erb:5: syntax error, unexpected tASSOC, expecting keyword_end
...action => "create"}, :remote => true do #output_buffer.safe_...
C:/Users/Lunasea/Web-Site/Standart/app/views/posts/_message_form.html.erb:12: syntax error, unexpected keyword_ensure, expecting keyword_end
C:/Users/Lunasea/Web-Site/Standart/app/views/posts/_message_form.html.erb:14: syntax error, unexpected $end, expecting keyword_end
The content of _message_form.html.erb:
<% if logged_in? %>
<!--<% form_for product, :url => {:action => 'add_to_cart', :id => product.id}, :remote => true do %>-->
<!--<%= form_remote_tag(:controller => "posts", :action => "create") do %>-->
<%= form_for{:controller => "posts", :action => "create"}, :remote => true do %>
<%= label_tag(:message, "What are you doing?") %><br />
<%= text_area_tag(:message, nil, :size => "60x2") %><br />
<%= submit_tag("Update") %>
<% end %>
<% end %>
You'd use a form_tag and pass :remote => true to it…
form_tag :url => {:controller => 'posts', :action => 'create'}, :remote => true
(Make sure you've included jQuery UJS or equivalent Prototype library, because Rails no longer includes the javascript inline like it used to.)
I cite here from the book Fernandez: The Rails 3 Way section 11.13
PrototypeHelper
PrototypeHelper has been heavily modified ... The following helper methods were removed and made available in an official Prototype Legacy Helper
...
form_remote_for
form_remote_tag
That is the reason for your error. You have to translate that to the new syntax with the option :remote => true to indicate a remote call (AJAX).
So the following should work:
<%= form_tag({:controller => "posts", :action => "create"}, {:remote => true}) do %>
...
<% end %>
See the API for Rails and search there for form_tag for additional information.
Your problem is that you use <!-- and --> to hide old code. Rails will still execute that code. Use the following format instead:
<% if logged_in? %>
<%-# form_for product, :url => {:action => 'add_to_cart', :id => product.id}, :remote => true do %>
<%-#= form_remote_tag(:controller => "posts", :action => "create") do %>
<%= form_for{:controller => "posts", :action => "create"}, :remote => true do %>
<%= label_tag(:message, "What are you doing?") %><br />
<%= text_area_tag(:message, nil, :size => "60x2") %><br />
<%= submit_tag("Update") %>
<% end %>
<% end %>
form_remote_tag is not there in the Rails 3
Use
form_tag :url => {...}, :remote => true
instead
What this means is that all previous remote_ helpers have been
removed from Rails core and put into the Prototype Legacy Helper. To
get UJS hooks into your HTML, you now pass :remote => true instead.
For example:
form_for #post, :remote => true
http://edgeguides.rubyonrails.org/3_0_release_notes.html
The error is saying there is a syntax problem in the message form template. My guess is that you are missing a <% end %> to close the do in your form_remote_tag call.
I have a partial called _avatar.html.erb
I want to pass in an id as a local variable called entity_id which will be the id of an object.
<% form_tag({:controller => "avatar", :action => "upload", :id => entity_id},
:multipart => true ) do %>
<fieldset>
<legend><%= title %></legend>
<% if avatar.exists? %>
<%= avatar_tag(avatar) %>
[<%= link_to "delete", {:controller => "avatar",:action => "delete",
:id => entity_id},:confirm => "Are you sure" %>]
...
Here is the call for the parital:
<%= render :partial => 'avatar/avatar', :locals => {:avatar => #avatar,
:title => #title, :entity_id => #board.id } %>
When I try this I get the following errors:
undefined local variable or method `entity_id' for #<ActionView::Base:0x2736bb0>
When I take that out I also get an error telling me it can't find the local variable "title".
Can anyone help this seems to be the correct way to do this.
Thanks in advance
Try using :id=>#entity_id (note the # symbol preceding the name). Likewise, #title, instead of "title".
I have a partial called _avatar.html.erb
I want to pass in an id as a local variable called entity_id which will be the id of an object.
<% form_tag({:controller => "avatar", :action => "upload", :id => entity_id}, :multipart => true ) do %>
<fieldset>
<legend><%= title %></legend>
<% if avatar.exists? %>
<%= avatar_tag(avatar) %>
[<%= link_to "delete", {:controller => "avatar",:action => "delete", :id => entity_id},:confirm => "Are you sure" %>]
...
Here is the call for the parital:
<%= render :partial => 'avatar/avatar', :locals => {:avatar => #avatar, :title => #title, :entity_id => #board.id } %>
When I try this I get the following errors:
undefined local variable or method `entity_id' for #
When I take that out I also get an error telling me it can't find the local variable "title".
Can anyone help this seems to be the correct way to do this.
Thanks in advance
Are you sure the error is coming from the partial? You are using entity_id in the form_tag. Where is it being defined? title isn't used in the partial. It is used inside of legend though. Is that defined?