I have a redmine installation running fine. I have an issue to disable the utf-8 enforcement tag when doing searches. This is because on my network there is a url policy check that will prevent me from opening the url containing the utf-8 enforcement parameter.
So I went to /usr/share/redmine/app/views/issues/index.html.erb and changed this line:
<%= form_tag({ :controller => 'issues', :action => 'index', :project_id => #project },
:method => :get, :id => 'query_form') do %>
to this
<%= form_tag({ :controller => 'issues', :action => 'index', :project_id => #project },
:method => :get, :id => 'query_form', :enforce_utf8 => false) do %>
but the utf8 enforcement parameter shows up
What am I doing wrong? Can I disable it on a global base?
Related
Normally its like:
resources :users
To keep a value ahead we can do like
scope :url do
resources :users
end
but, issue is that I have the just variable in front of the routes not a fixed value with few conditions for it.
Example in rails 2. and want to convert the routing accoding to rails5
map.with_options :controller => 'users' do |user|
user.forgot_user ':url/users/forgot', :action => 'forgot', :url => /([a-zA-Z0-9\-]*)/
user.user ':url/users/retrieve', :action => 'retrieve', :url => /([a-zA-Z0-9\-]*)/
user.login ':url/users/login', :action => 'login', :url => /([a-zA-Z0-9\-]*)/
user.logout ':url/users/logout', :action => 'logout', :url => /([a-zA-Z0-9\-]*)/
user.new_user ':url/users/new', :action => 'new', :conditions => { :method => :get }, :url => /([a-zA-Z0-9\-]*)/
user.users ':url/users/:id', :action => 'show', :conditions => { :method => :get }, :url => /([a-zA-Z0-9\-]*)/
end
Thanks in advance.
scope "/(:subdomain)", :defaults => {:subdomain => "default"} do
...
end
use subdomain as a variable.
I have the following code in my Rails app:
link_to('???',{:controller => 'profile', :action => 'show', :id => id})
I want to get rid of '???' and it to show the dynamically generated URL. How do I this? It's kind of like what the autolink gem does, but I want Rails to convert URL options into text, not vice versa.
link_to(nil,{:controller => 'profile', :action => 'show', :id => id})
From the link_to documentation:
If nil is passed as the name the value of the link itself will become the name
Use url_for() to get the string.
url_for({:controller => 'profile', :action => 'show', :id => id)}
In the code:
url_hash = {:controller => 'profile', :action => 'show', :id => id}
link_to(url_for(url_hash), url_hash)
See this question to also get the host name:
url_hash = {:controller => 'profile', :action => 'show', :id => id}
link_to("#{request.host_with_port}#{url_for(url_hash)}", url_hash)
I have a link_to like this:
<%= link_to "Nuevo Contrato", {:controller => "hotels", :action => "edit", :id => #hotel_id, :selected_tab => "4"}, :class => "new_link" %>
There's a way to send those parameters not using the query string for it? (using post instead of a get) ??
Thank you!
I already tried:
<%= link_to "Nuevo Contrato", {:controller => "hotels", :action => "edit", :id => #hotel_id, :selected_tab => "4"}, {:method => :post,:class => "new_link"} %>
And it keeps doing the same thing...!
Add a supported HTTP verb in the method option.
<%= link_to "link", {:method => :post ...} %>
I think you can just add :method => :post to the options of link_to.
Here are the docs (for Rails 3, but I think this still holds true for Rails 2 also) http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
EDIT FOR UPDATED QUESTION
:method => :post belongs in the HTML options, not the URL options. This is not very obvious from the documentation.
<%= link_to "Nuevo Contrato", {:controller => "hotels", :action => "edit", :id => #hotel_id, :selected_tab => "4"}, {:method => :post, :class => "new_link"} %>
Is it possible to submit another parameter outside the form data in rails? My problem is that I render different forms for different classes and send them to the same create method. I would like to send the class with the form (as value not as key in the hash).
Something like the :type parameter (that actually doesn't work)
<%= form_for(#an_object, :url => { :controller => :a_controller, :action => :create },
:type => #an_object.class.to_s.underscore) do |f| %>
The post message looks like:
{"commit"=>"Create Class of an Object",
"authenticity_token"=>"/iqu0A8/AocDT3HyjL5/+bKZiLkyr4FE71u/mc8Wx0Y=",
"utf8"=>"✓",
"class_of_an_object"=>{"name"=>"a name",
"description"=>"a description"}}
and I would have a "type" => "class_of_an_object", but directly in the hash an not within the "class_of_an_object" hash.
<%= form_for #an_object,
:url => { :controller => :a_controller,
:action => :create,
:type => #an_object.class.to_s.underscore } do |f| %>
And I prefer to use named routes
<%= form_for #object, :url => object_path(#object, :type => "whtever"), :html => {:method => :post} do |f| %>
This works for me:
<%= form_for #foo, :url => foo_path(:type => "whatever"), :html => {:method => :post} do |f| %>
I have a bilingual site with nice URLs for SEO. Using Ruby on Rails 2.3.10.
routes.rb fragment:
map.connect 'order-jira-hosting/:option.html',
:controller => 'order', :action => 'index', :locale => 'en'
map.connect 'order-jira-with-greenhopper-hosting/:option.html',
:controller => 'order', :action => 'index', :locale => 'en', :greenhopper => true
map.connect 'zamow-hosting-jira/:option.html',
:controller => 'order', :action => 'index', :locale => 'pl'
map.connect 'zamow-hosting-jira-z-greenhopper/:option.html',
:controller => 'order', :action => 'index', :locale => 'pl', :greenhopper => true
As you can see, :locale and :greenhopper are "hidden" in the URL.
There is a switch so that you can change the language of the current page. See my views/layouts/default.erb:
<%= link_to image_tag('icons/polish.png', :alt => 'polski'), { :locale => 'pl'}, :class => 'a' %>
<%= link_to image_tag('icons/english.png', :alt => 'English'), { :locale => 'en'}, :class => 'a' %>
I simply don't specify a controller and action so that I am redirected to the current controller and action with different locale. Unfortunately, :greenhopper parameter gets lost.
I am at /order-jira-with-greenhopper-hosting/11.html
(:option => 11, :locale => 'en', :greenhopper => true)
Generated links for switching languages are /order-jira-hosting/11.html and /zamow-hosting-jira/11.html
(:option => 11, :locale => 'pl' and 'en', :greenhopper => false)...
...But they should be /order-jira-with-greenhopper-hosting/11.html and /zamow-hosting-jira-z-greenhopper/11.html
(:option => 11, :locale => 'pl' and 'en', :greenhopper => true)
How to use link_to method so that all parameters passed to controller are preserved? Thanks for your help.
You can base the hash you send to link_to off the params hash, which, if you passed it into link_to as-is, would reload the current page. You can use Hash.merge(other_hash) to reset the :locale key for each link:
<%= link_to '<polish image />', params.merge({:locale => 'pl'}), :class => 'a' %>
Now, params does contain controller and action keys, but they're the controller and action that generated the current page, so the link should behave just like a page refresh, with only the parameters you changed via params.merge changing.
Hope this helps!
PS: params.merge doesn't change the params hash, if you're concerned about that - the result of the merge is returned as a new hash.