I have a dropdown selector next to a search box in my navigation bar.
<select>
<option> All </option>
<option> Ask </option>
<option> Offer </option>
</select>
<form class="navbar-form navbar-right">
<%= form_tag(i_want_to_choose_this_path, :method => :get) do %>
<%= text_field_tag :search, nil,
{:id => "search-query-2", :placeholder => "Search favors..."} %>
<%= hidden_field_tag :use_keywords, "true" %>
<%= hidden_field_tag :wide_search, "true" %>
<% end %>
</form>
How can I use the selected option to change the path the search form will route to, to either asks_path, offers_path or all_path? The options are just words that relate to the paths I want to choose. They do not exist in any models. I looked at category_select, but it seems to require that my options are related to a model, which they don't, and I'm not sure how they would, because the paths point to different models.
Related
I am currently developing a redmine Plugin,
so far it went well. But since I integrated the plugin into a project i cant use form_for to create an edit view.
Edit View:
Formular
<div class="box tabular">
<div class="splitcontent">
<div class="splitcontentleft">
<%= form_for (#customer) do |f| %>
<div class="splitcontent">
<div class="splitcontentleft field_name">Name </div>
<div class="splitcontentright"><%= f.text_field :name, :size => 20, required: true %></div>
</div>
</div>
<hr />
<%= render :partial => '/inventory_customers/form_custom_fields' %>
<div></div>
</div>
<div><%= f.submit submit_text %></div>
<% end %>
Controller
before_filter :find_project
...
def edit
#customer = InventoryCustomer.find(params[:id])
end
...
private
def find_project
# #project variable must be set before calling the authorize filter
#project = Project.find(params[:project_id])
end
def customer_params
params.require(:inventory_customer).permit(:name, :sap_id, :sap_name, :address, :partner, :partner_text, :active)
end
Error Message
Started GET "/redmine/projects/inventory development/prototyp/inventory_customers/3/edit" for 172.20.1.197 at 2016-08-03 16:07:45 +0200
Processing by InventoryCustomersController#edit as HTML
Parameters: {"project_id"=>"inventory-development", "id"=>"3"}
Current user: COAH (id=38)
Rendered plugins/prototyp/app/views/_inventory_menu.html.erb (0.7ms)
Rendered plugins/prototyp/app/views/inventory_customers/_form.html.erb (1.6ms)
Rendered plugins/prototyp/app/views/inventory_customers/edit.html.erb within layouts/base (2.9ms)
Completed 500 Internal Server Error in 7ms (ActiveRecord: 0.3ms)
ActionView::Template::Error (No route matches {:action=>"show", :controller=>"inventory_customers", :id=>nil, :project_id=>#<InventoryCustomer id: 3, name: "blub", partner: false, sap_name: "asdasd", address: "sadasd", active: true, sap_id: "">} missing required keys: [:id]):
2: <div class="box tabular">
3: <div class="splitcontent">
4: <div class="splitcontentleft">
5: <%= form_for (#customer) do |f| %>
6: <div class="splitcontent">
7: <div class="splitcontentleft field_name">Name </div>
8: <div class="splitcontentright"><%= f.text_field :name, :size => 20, required: true %></div>
lib/redmine/sudo_mode.rb:63:in `sudo_mode'
If i remove the form_for i can load the edit view but then i dont see a way to edit the object.
Since i just started with rails and redmine i have absolutly no idea how to fix the error or how i can do a work arround.
Use form_tag(path, :method=> 'put', :multipart => true ) do instead of form_for
path is something like customer_path.
Make sure to use another path for editing (singular) than for creating (plural, no id needed)
In my Rails app, the labels for the fields on the login page are way too close to the fields themselves, making it look cramped. I want to add space between them, but am not sure how.
I have Rails 4 with simple_form, bootstrap 3, and devise installed.
This is my app/views/devise/sessions/new.html.erb code:
<div class="row">
<div class="col-xs-4">
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name), html: {class: "well"}) do |f| %>
<fieldset>
<legend>Log in</legend>
<%= f.input :email %>
<%= f.input :password %>
<% if devise_mapping.rememberable? -%>
<div class="field">
<%= f.input :remember_me, as: :boolean %>
</div>
</fieldset>
<% end -%>
<div class="actions">
<%= f.button :submit, "Log in" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
</div>
<div class="col-xs-8">
<h2>Signing in is easy and secure</h2>
</div>
</div>
And here is the entire github repo: https://github.com/yamilethmedina/wheels_registration
I've been looking in my bootstrap.css file and can't find relevant classes. What do you think I should do next?
You could add your own label with space after the custom label.
<%= f.input :email, label: 'Email ' %>
<%= f.input :password, label: 'Password ' %>
Or you could use tools like chrome dev tools to inspect the label element to see what class the labels are given and then add some custom css. example .label-class { margin-right: 10px; }
Guys that is my code thing is I want to select a parent subject and upon selection I need to use that selected subject to list the topics within it in the parent field how can i do that?
<label>Parent Subject</label>
<div class="field">
<%= collection_select :topic, :subject_id, Subject.all, :id, :name %>
</div>
<label>Parent Topic</label>
<div class="field">
<%= collection_select :topic, :parent_id, ?????, :id, :name %>
</div>
Would this help? Rails dependent collection_select fields in form
If not, I am about to build something and might be happy to share it if it isn't to ugly!
I'm in the process of building a rails 4 app and I've run into a snag. When I go to the sign in page and enter the information correctly everything works
If I go to sign in but I don't input one of the required fields (name, email, etc) it will put up an error message saying 'Please review the problems below:' but the specific error messages, such as 'email can't be blank' do not show up.
The errors displayed properly before I added styling..
The code is here:
https://github.com/mikejames386/Black-Fret
I'm currently working off the devise branch.
This is the first time I've ever asked a question on stackoverflow so please let me know if there is any other info needed.
<div class="container">
<div id="form_container"><!-- start form_container -->
<h1>New Artist</h1>
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= f.error_notification %>
<h2>Artist or Band Name</h2>
<div class="form_section">
<div class="field">
<%= f.label :name %>
<%= f.text_field :name %>
</div>
<br class="clear_both"/>
</div> <!-- end form_section -->
<h2>Primary Contact</h2>
<div class="form_section">
<div class="field">
<%= f.label :primary_first_name, 'First Name'%>
<%= f.text_field :primary_first_name %>
</div>
<div class="field">
<%= f.label :primary_last_name, 'Last Name'%>
<%= f.text_field :primary_last_name %>
</div>
<div class="field">
<%= f.label :email, 'Email'%>
<%= f.text_field :email %>
</div>
<br class="clear_both"/>
</div> <!-- end form_section -->
<h2>Password</h2>
<div class="form_section">
<div class="field"><%= f.label :password %>
<%= f.password_field :password %></div>
<div class="field"><%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %>
</div>
<br class="clear_both"/>
</div>
<h2>Members</h2>
<div class="form_section">
<p>member multi-add goes here</p>
</div> <!-- end form_section -->
<%= f.submit "Add Artist", :class =>'btn btn-custom' %>
<% end %>
</div> <!-- end form_container -->
Errors on Devise log-in page are added as flash messages.
In order to capture them, add following lines in app/views/layouts/application.html.erb
<% flash.each do |name, msg| %>
<%= content_tag :div, msg %>
<% end %>
As per Devise Documentation
Remember that Devise uses flash messages to let users know if sign in
was successful or failed. Devise expects your application to call
flash[:notice] and flash[:alert] as appropriate. Do not print the
entire flash hash, print only specific keys. In some circumstances,
Devise adds a :timedout key to the flash hash, which is not meant for
display. Remove this key from the hash if you intend to print the
entire hash.
I have Devise set up on rails 4 with my app and I actually have a Devise User model, a registration controller (which youdon't need) and a Devise views section. You may want to follow this tutorial https://github.com/plataformatec/devise, if you scroll down a bit you will see configuring views. The below will get put into your user model and the validatable is for validations on email and password which may be why the validations are not working properly just a thought. But I hope this tutorial gives you some guidance.
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
After you install Devise and add it to your Gemfile, you need to run the generator:
rails generate devise:install
After you install Devise and add it to your Gemfile, you need to run the generator:
The generator will install an initializer which describes ALL Devise's configuration options and you MUST take a look at it. When you are done, you are ready to add Devise to any of your models using the generator:
rails generate devise MODEL
Replace MODEL by the class name used for the applications users, it's frequently User but could also be Admin. This will create a model (if one does not exist) and configure it with default Devise modules. Next, you'll usually run rake db:migrate as the generator will have created a migration file (if your ORM supports them). This generator also configures your config/routes.rb file to point to the Devise controller.
Configuring views
We built Devise to help you quickly develop an application that uses authentication. However, we don't want to be in your way when you need to customize it.
Since Devise is an engine, all its views are packaged inside the gem. These views will help you get started, but after some time you may want to change them. If this is the case, you just need to invoke the following generator, and it will copy all views to your application:
rails generate devise:views
I have a search form on an index page for my Properties model which is using both Ransack and Geocoder to search the Properties model fields as well as narrow the results down based on distance from an address input by the user in the search form.
The address and distance are captured in the form with :nearaddress and :distance, respectively, which I send in params[:near]. I am checking for the presence of them in the controller index action following this answer. The result is “undefined method `merge' for nil:NilClass” when navigating to /properties, so the view will not render. How do I enable these non-model form parameters to be passed to the controller properly? I think this might be a strong parameters issue but I'm stuck on how to permit these attributes that aren't in the Properties model. The error highlights the "f.text_field :nearaddress" line.
index.html.erb:
...form fields that work when excluding the two that follow...
<div class ="field">
<%= f.label :nearaddress, "Address" %>
<%= f.text_field :nearaddress, params[:near] %>
</div>
<div class ="field">
<%= label_tag :distance %>
<%= text_field_tag :distance, params[:near] %> miles
</div>
<div class="actions"><%= f.submit "Search" %></div>
<% end %>
properties_controller.rb:
def index
if params[:near].present? && (params[:near].to_i >0)
#search = Property.near(params[:near]).search(params[:q])
else
#search = Property.search(params[:q])
end
#properties = #search.result(:distinct => true).paginate(:page => params[:page])
...
end
I was able to resolve this problem by removing the "f." and adding "_tag" to the :nearaddress field as well as specifying the params in the controller index:
<%= label_tag :nearaddress, "Near Address" %>
<%= text_field_tag :nearaddress, params[:near] %>
<%= label_tag :distance, "Distance From Address (mi)" %>
<%= text_field_tag :distance, params[:near] %>
<div class="actions"><%= f.submit "Search" %>
<% end %>
if params[:distance].present? && (params[:distance].to_i >0) && params[:nearaddress].present?
#search = Property.near(params[:nearaddress],params[:distance]).search(params[:q])
else
#search = Property.search(params[:q])
end