simple-form

Add Image Tag to Checkbox Input Field with Rails 4 and Simple Form

試著忘記壹切 提交于 2019-12-13 21:00:27
问题 Using Rails 4, Simple_Form and Bootstrap 3, I am trying to get my output HTML look like this to work with some front end styling: <div class="checkbox"> <input value="0" type="hidden" name="member[remember_me]"> <label class="boolean optional" for="member_remember_me"> <input type="checkbox" value=""> <i class="input-helper"></i> Keep me signed in </label> </div> In my form, I have this: <%= f.input :remember_me, class: 'checkbox inline', type: 'checkbox', as: :boolean if devise_mapping

Rails 5 - how to upload excel files - tutorials not working out

為{幸葍}努か 提交于 2019-12-13 09:33:44
问题 I am trying to upload an excel file to my Rails 5 app. I have tried this tutorial, and this one, and this one. I can't get any of them to work. I have a namespaced model called: class Randd::Field < ApplicationRecord require 'csv' I have tried each of these methods in my model: def self.import(file) CSV.foreach(file.path, headers: true) do | row | Randd::Field.create! row.to_hash end end def self.import(file) CSV.foreach(file.path, headers: true) do |row| randd_field_hash = row.to_hash #

When I click submit button in my form, create action is supposed to work but it is rather processed by new action

感情迁移 提交于 2019-12-13 06:51:06
问题 In my application, I have a form that is supposed to be processed by create action but it is rather processed by new action. This problem is happening in my post task form, but in my other form (registration form), it is working very well (it is processed by create action). So I thought maybe the culprit is in my model relationships so I will post it here as well: User model has_many :client_relationships, class_name: "Task", foreign_key: "client_id", dependent: :destroy has_many :worker

specify values in Simple Form Association

假如想象 提交于 2019-12-13 06:16:44
问题 I am trying to select specific record but when trying to save , employee_id is saved with a null value, and without putting any condition it works normally , is there any way to solve this ? <%= f.association :employee , collection: Employee.where('student_advisor' => true).map(&:full_name) %> 回答1: This is what works for me: <%= f.association :employee, :collection => Employee.where('student_advisor' => true), :label_method => :full_name, :value_method => :id %> Though IMHO its better to set

Rails 4 - Country Select & Simple Form

心不动则不痛 提交于 2019-12-13 04:14:23
问题 I am trying to make an app in Rails 4. I use simple form for forms and country_select gem for country lists. I have an address model, which includes this method: def country_name self.country = ISO3166::Country[country] country.translations[I18n.locale.to_s] || country.name end When I try to save a new address, I get this error: undefined method `translations' for "Australia":String Can anyone see what's wrong with this method definition? If I change my view to: <% if @profile.addresses.any?

How do I get the country_select gem and simple_form to work from scratch?

自作多情 提交于 2019-12-13 03:59:56
问题 I just want a simple country dropdown, prioritized for my purposes (i.e. to include the states within the country selected). In fact, I only want 1 or 2 countries. I am using Simple_Form and their documentation say that in order to get access to this: f.input :shipping_country, priority: [ "Brazil" ], collection: [ "Australia", "Brazil", "New Zealand"] I just need to include this in my Gemfile: gem 'country_select' But I am confused...I don't have to run a migration to store the country

Rails3+Devise+Simple_form: Singular resource & simple_form_for errors in path helper

喜夏-厌秋 提交于 2019-12-13 03:44:55
问题 Got 2 questions: How can I get the simple_form_for to work with singular resource :foo_object that's associated to :users (see code excerpts below)? I get NoMethodError: undefined method foo_objects_path for @foo in the simple_form_for line. foo_object_path has a valid path but it seems simple_form_for is using the plural version. I've google'd & read SO posts regarding singular resource and path issues, but haven't found a solution to this. Do I need to create a nested resource for :foo

Rails 4 -Simple Form how to save key and display value

断了今生、忘了曾经 提交于 2019-12-13 03:00:41
问题 I'm trying to make an app in Rails 4. I use simple form for forms. I have an attribute called 'self_governance' in my model. I've written a helper method so that I can define 5 levels which can be stored for this attribute, but which are displayed to the user as options (rather than numbers 1 .. 5). In my helper, I have: module PreferencesHelper def self_gov_selector [ [ 'tier 1','1'], [ 'tier 2','2'], [ 'tier 3','3'], [ 'tier 4','4'], [ 'tier 5','5'], ] end In my form, I then have: <%= f

Rails deletes record on edit and not submit

…衆ロ難τιáo~ 提交于 2019-12-13 01:24:38
问题 Having the following associations: Workout has_many workout_sets through ... workout_set has_many workout_steps through ... When editing an object I'm experiencing the following issue: 1) go to /model/:id/edit 2) checking the db, once the page loads the top level attributes (the non-nested ones) are deleted from the db once the page loads, but the select marks as selected the correct values, as if in the moment of the load the data was correct. 3) leaving the page without saving (returning to