How to Handle Single Table Inheritance in Simpleform So a Single Helper Handles All Models

How do you handle single table inheritance in SimpleForm so a single helper handles all models?

Specify :url=> networking_event_session_path in the simple_form_for.

Something like this:

<%= simple_form_form @session, :url => networking_event_session_path %>

How to show more attributes in each element of the collection with collection_select

As stated in the discussion, you needed to declare a method in your model's rb file like this:

def custom_name
"#{style.name}. #{date}"
end

And change the :style_name parameter to :custom_name

How to show select menu for two models?

I think better way to do is to use polymorphic association.

class Price
belongs_to :pricable, polymorphic: true
end

class Product
has_one :price, as: :priceable
end

class Service
has_one :price, as: :priceable
end

Then, in your form, you can use:

<%= form_for [@priceable, Price.new]

where @priceable is a product or a service.

Using blank? or present? in model-scopes in Ruby on Rails

Try

scope :myScope1, where("myField IS NULL or CAST(myField as text) = ''")

It's not that simple as blank?, but I can't see a simple enough solution.



Related Topics



Leave a reply



Submit