Rectangle 27 8

simple_fields_for
<%= simple_form_for :topic, :url => forum_topics_path do |topic_builder| %>
  <%= topic_builder.input :name, :label => 'Topic' %>
  <%= topic_builder.simple_fields_for :post do |post_builder| %>
    <p>First Post:</p> 
    <%= post_builder.input :title, :input_html => { :size => 30 } %>
    <%= post_builder.input :body, :as => :text, :input_html => { :rows => 20, :cols => 50, :class => 'resizable' } %>
  <% end %>
  <%= topic_builder.submit 'Save' %>
<% end %>

simple form - rails simple_form two models - Stack Overflow

ruby-on-rails simple-form
Rectangle 27 1

= form_tag action_path do

      = fields_for :model_a do |a|
        = a.text_field :name

      = fields_for :model_b do |b|
        = b.text_field :name

      = submit_tag 'Submit'

simple form - rails: a single simple_form with two unrelated models? -...

ruby-on-rails simple-form
Rectangle 27 1

the sample code you supplied does not resemble either doctrine 1 or doctrine 2. by default, tables in doctrine 1 extend \Doctrine_Table. additionally the database table name is defined in the corresponding model file, not as a property of the table class itself. i suggest you read at least the first few chapters of the documention and look at some examples there

php - Simplest way to extend doctrine for MVC Models - Stack Overflow

php model-view-controller doctrine models
Rectangle 27 0

I read that fetch() was an asynchronous operation, therefore when you fetch a collection, the ajax call will be sent and then your code will continue being run just like nothing happened.

fetch()
events.fetch({success: function (models) {
    tracks.fetch({success: function (models) {
        new EventsView({el: $("#calendar"), collection: events, collection2: tracks}).render();
    }});
}});

javascript - Backbone Collection is populated with models but cannot p...

javascript json backbone.js
Rectangle 27 0

= form_tag action_path do

      = fields_for :model_a do |a|
        = a.text_field :name

      = fields_for :model_b do |b|
        = b.text_field :name

      = submit_tag 'Submit'

simple form - rails: a single simple_form with two unrelated models? -...

ruby-on-rails simple-form
Rectangle 27 0

There's another approach that I'm using and it works great. Ryan Bates (RailsCasts) has created a gem to handle this.

simple form - rails simple_form two models - Stack Overflow

ruby-on-rails simple-form
Rectangle 27 0

You probably want an elsif here, rather than 3 separate blocks. Try something to the effect of:

if user_signed_in?
  ...
elsif admin_signed_in?
  ...
elsif company_user_signed_in?
  ...
elsif params[:action] == 'index'
  ...
elsif params[:action] == 'admin'
  ...
elsif params[:action] == 'company_user'
  ...
else
  # handle any other case where none of above conditions are met, e.g. params[:action] == 'foobar'
end

Thanks, that's along the same thought I had with the eventual code that used. See my code for explanation.

No problemo. For future reference, it's a bit of poor form on StackOverflow for you to take someone's answer, re-type it, and then award yourself the correct solution. If a concept helps you solve your question in the future, you should mark it as the answer rather than re-hashing it.

That's what I would do if your answer actually helped solve my problem but I solved it with help from other sources. If you look at my solution, you can see that it's very different than what you wrote even though it has similar ideas. In fact, my original broken code also had the same idea but it doesn't really work.

Solution looks the same to me, but what do I know about what went through your head. For what it's worth, your last else statement has a condition params[:action] == 'company_user' that doesn't do anything.

I just tried your first method and it seems to works as well. I can see why you chose to refactor it. It's cleaner. Thanks.

ruby on rails - Need a simple syntax when using multiple devise user m...

ruby-on-rails ruby devise ruby-on-rails-4
Rectangle 27 0

the sample code you supplied does not resemble either doctrine 1 or doctrine 2. by default, tables in doctrine 1 extend \Doctrine_Table. additionally the database table name is defined in the corresponding model file, not as a property of the table class itself. i suggest you read at least the first few chapters of the documention and look at some examples there

php - Simplest way to extend doctrine for MVC Models - Stack Overflow

php model-view-controller doctrine models
Rectangle 27 0

There's another approach that I'm using and it works great. Ryan Bates (RailsCasts) has created a gem to handle this.

simple form - rails simple_form two models - Stack Overflow

ruby-on-rails simple-form
Rectangle 27 0

def show
  @project_questions = @project.project_questions.build
end
<%= simple_form_for @project_questions do |f| %>
  <%= f.input :title%>
  <%= f.input :content %>
  <%= f.button :submit %>
<% end %>

Thanks, I tried this, but then I get an error that says: No route matches {:action=>"new", :controller=>"project_answers", :id=>"70", :project_id=>nil, :project_question_id=>nil, :format=>nil} missing required keys: [:project_id, :project_question_id]

Rails 4 -Nested Models and Simple Form partial - Stack Overflow

ruby-on-rails simple-form
Rectangle 27 0

Another option is to create an isolated datacontext that maintains the models of observables. the viewmodels all look to the datacontext for their data and refer to the same objects, so when one updates, they all do. The VM's dependency is on the datacontext, but not on other VMs. I've been doing this lately and it has worked well. Although, it is much more complex than using pub/sub.

If you want simple pub/sub, you can use Ryan Niemyer's library that he mentioned or use amplify.js which has pub/sub messaging (basically a messenger or event aggregator) built in. Both are lightweight and decoupled.

Thanks for your answer and letting me know about Amplify. However, I need something that's completely local, without the need for a global topic string. What do you think of my solution?

data binding - Simple, clean way to sync observables from different vi...

data-binding knockout.js observer-pattern
Rectangle 27 0

Ok, you could do the following, but I wouldn't recommend it. Create a static method similar to the following

public static IHtmlString DisplayProperty(object obj, string property) {
    return new HtmlString(TypeDescriptor.GetProperties(obj)[property].GetValue(obj).ToString());
}

Then in your cshtml file make the following call (make sure to using your proper namespace)

<tbody>
    @foreach (var item in Model) {
    <tr>
        <td>@DisplayProperty(x, "RateCodeName")</td>
        <td>@DisplayProperty(x, "Year")</td>                            
        <td>@DisplayProperty(x, "Rate")</td>
        <td>>@DisplayProperty(x, "Comment")</td>
    </tr>
    }
</tbody>

I wouldn't recommend this though but it is a solution to your problem that doesn't require a model.

linq - Simplest Way To Do Dynamic View Models in ASP.NET MVC 3 - Stack...

linq dynamic asp.net-mvc-3
Rectangle 27 0

var events = new Events();
var tracks = new Tracks();

events.fetch();

new EventsView({el: $("#calendar"), collection: events, collection2: tracks}).render();
new AddSessionView({ collection: events}).render();

unfortunately this didn't do it. i am still get the same readout in my console. I did notice a difference between the data structure of my collection compared to say... jsfiddle.net/YcFmB Maybe thats the problem, I just don't know why that would be...

i would make your own fetch function. make the ajax call in there and make sure you are adding the data to the collection correctly from your ajax call

javascript - Backbone Collection is populated with models but cannot p...

javascript json backbone.js
Rectangle 27 0

if you only want products back, just add both joins:

@products = Product.joins(:release,:artists).where('products.cat_no LIKE :term OR releases.title LIKE :term OR artists.name LIKE :term', :term => "%#{params[:search]}%").all

You may also need group_by to get distinct products back.

if you want polymorphic results, try 3 separate queries.

HasManyThroughAssociationNotFoundError in ProductsController - Could not find the association :releases in model Product

note the singular ':release' in the join association name, while plural 'releases.title' in the table name. Crucial :)

Yes, I have it like that. As I test I removed all references to release and the error is always the same!?!

oh your error is simply cos you have a typo in product: :through => :release not :releases, the through association here is a belongs_to

Rails 3.1 - Simple search across three (or more) models? - Stack Overf...

ruby-on-rails ruby-on-rails-3 activerecord
Rectangle 27 0

You use f.simple_fields_for in pqps, but f is not defined anywhere. You have to define it using simple_form_for somewhere. I don't know exactly where it depends on your own needs, but if, say, the whole form is inside _pqps:

<div class="containerfluid">
  <div class="row">
    <div class="col-md-10 col-md-offset-1">
      <%= simple_form_for @project do |f| %>
        <% f.simple_fields_for :project_questions, @project.project_questions.build do |f| %>
          # ...
        <% end %>
      <% end %>
    </div>
  </div>
</div>

If form "starts" outside "_pqps" partial, then you have to pass f as a local parameter:

<%= render 'project_questions/pqps', f: f %>

Thanks, I tried this but I get an error that says: undefined local variable or method `f' for

That error means you are trying to access f somewhere outside of the block. Make sure you access it between <%= simple_form_for @project do |f| %> and <% end %> for that block.

Rails 4 -Nested Models and Simple Form partial - Stack Overflow

ruby-on-rails simple-form
Rectangle 27 0

There is a quite nice natural language processing for node.js called natural. It's not currently built for running in the browser, but the authors have stated that they want to fix that. Most of it might even work already, using something like browserify or Require.JS.

Thanks for the tips: on natural, which looks like a good package to watch; and also browserify, of which I was also unaware.

Basic NLP in CoffeeScript or JavaScript -- Punkt tokenizaton, simple t...

javascript nlp coffeescript user-experience tokenize
Rectangle 27 0

I don't think there is a simple explanation why any approach is the best in any circumstance. A significant amount of questions on Stack Overflow are question on how to design relations between their models. It's a complicated topic and the right solutions require intimate knowledge of the problem you are solving. And even then, you probably won't get it right the first couple of times.

The best way so far is to completely work TDD/BDD on this matter and let the tests/specs drive out your design. And don't be afraid to refactor is you find a better way. Most of the time you will only see the right solution after you've tried a couple of wrong ones. You'll get to know the edge cases. As Ward Cunningham puts it in his "Technical Debt" analogy: "Refactor afterwards as if you knew what you were doing from the start". Be sure to have the acceptance tests to verify its behavior afterwards though.

Getting more specific to your problem. There is a third option and that is to completely split up the classes, each with their own table. I've tried it in my current project and I like it. You don't need to define something like a user, if that doesn't make sense in your business domain. If they have shared behavior, use mixins. The most important caveat is that it's not straight forward to have them login through the same form anymore.

I have Admin, Recruiter, Supplier and Visistor models. They are all separate models, sharing some behavior with mixins. They all have their own namespaced controllers to act on. For instance, all actions for the admins are in the Backend namespace. There is a namespaced ApplicationController too. The Backend::ApplicationController simply specifies before_filter :authorize_admin!. No switching, no complicated case statements, nothing.

You need to pay special attention to conventions. If you use the same names across the models, your mixins can become super easy. Read up on ActiveSupport::Concern to make mixins even easier to work with. I have a mixin like this:

And in my routes:

So, to conclude. Any architecture will work. STI and polymorphism have their place, but be sure to model your architecture according to your domain. Ruby is a very flexible language and you can use this to your advantage. Devise and CanCan are excellent gems and can handle these situations with ease. I showed you my solution for a project I'm currently working on. It works well for me, but I cannot say if it works right for you. Don't be afraid to experiment and refactor when you feel you've made a bad decision, rather than keep patching up your original idea.

PS. Speaking of STI and relations: they work excellent together too. You can define relations from one subclass to another subclasses. It will all work as expected.

I read several other articles referencing Modules and mixins, yet I don't have any idea what they are. Is there a good resource online that you know of where I can read up on what they are and how to use them? I couldn't glean much from the official Rails docs...

Modules aren't Rails specific, so they are not actively mentioned in the Rails docs. Any documentation on Ruby metaprogramming will mention them extensively, because they are an important part of Ruby. I learned the most from Dave Thomas' screencasts. Not only good for learning Ruby, but learning OO in general.

I've been reading up on Modules and mixins--courtesy of the Picaxe book--but all the examples I've found thus far talk about Modules and mixins in a pure Ruby environment, not within Rails. Where do I define Modules in Rails?

Rails: PolyMorphic or STI or something else for User management? - Sta...

ruby-on-rails polymorphic-associations sti
Rectangle 27 0

It is not exactly 10 lines of code (although you could strip it down to your liking), but I use pub/sub messages between view models for this situation.

The basic idea is just to create a ko.subscribable and use topic-based subscriptions. The library extends subscribables to add subscribeTo, publishOn and syncWith (both publish and subscribe on a topic). These methods will set up the proper subscriptions for an observable to automatically participate in this messaging and stay synchronized with the topic.

Now your view models do not need to have direct references to each other and can communicate through the pubsub system. You can refactor your view models without breaking anything.

Like I said you could strip it down to less than 10 lines of code. The library just adds some extras like being able to unsubscribe, being able to have control over when publishing actually happens (equalityComparer), and you can specify a transform to run on incoming values.

Cool. It looks like you just uploaded that project. I'll probably find some uses for it. But I think that for my question, it's not so good. The publish method requires modifying the independent view models and imposes a dependency (published name) between them.

Yes, I guess if your goal is to have a 3rd party (view model) keep the other two in sync with each other, then maybe the library is not perfect for that situation. Of your options, I think that subscriptions to each other would work pretty well. You could add an extension that takes in an observable to stay in sync with that sets up both subscriptions. At least you could reuse it then. It might even be similar to the postbox idea, it would just use the actual observables rather than topics.

Another thought about using pub/sub. I suppose that your third view model could be the one to add the subscriptions and manage the topic. Then, the individual view models would not need to change or even know that they are participating in that syncing.

Ryan, can you take a look at the solution I came up with and let me know what you think?

Love the knockout-postbox library! I recommend it to anyone needing to sync variables or create dependencies without modifying the ko.computed() function.

data binding - Simple, clean way to sync observables from different vi...

data-binding knockout.js observer-pattern
Rectangle 27 0

I'm also new to Backbone but maybe this helps. Have you tried to convert the models property of your Collection object to JSON, like:

JSON.stringify(collection.models)
[ ]

javascript - Backbone Collection is populated with models but cannot p...

javascript json backbone.js
Rectangle 27 0

As someone who has written his own PHP framework, and with the same sensibility as yours, I can tell you that using a framework is a fine thing to do. That said, start by writing your own - you'll gain greater appreciation for the true structure and utility of a framework.

You'll want to learn about the Singleton object pattern. It is a major differentiator in the kinds of objects you can develop in your framework.

When you have written a few models that your files/controllers (presuming MVC) include, you will begin to see where to abstract a 'base mode' from which others extend (hint: the DB singleton).

When you start pulling in configs and the like, then you'll have your first framework object from which all other bases do their extension.

@Charles that's not an intelligent engineering proposition. Every pattern is appropriate in one place or another. For a tragically-simple framework, a DB singleton is a fine solution.

Singletons are rarely appropriate in any modern PHP framework. If you need a global, use a global. You get the same highly-coupled difficult-to-test result without the silly overhead.

database - Is there a (simple) way to separate models in pure PHP, and...

php database oop design frameworks