ruby-on-rails-3

How to test routes in a Rails 3.1 mountable engine

萝らか妹 提交于 2019-12-28 13:42:08
问题 I am trying to write some routing specs for a mountable rails 3.1 engine. I have working model and controller specs, but I cannot figure out how to specify routes. For a sample engine, 'testy', every approach I try ends with the same error: ActionController::RoutingError: No route matches "/testy" I've tried both Rspec and Test::Unit syntax (spec/routing/index_routing_spec.rb): describe "test controller routing" do it "Routs the root to the test controller's index action" do { :get => '/testy

RSpec2 and Capybara

独自空忆成欢 提交于 2019-12-28 13:29:12
问题 Capybara is confusing me. If I use Capybara in combination with Ruby on Rails 3 and RSpec 2, then in RSpec request tests, the following matcher works: response.body.should have_selector "div.some_class" The response object has the class ActionDispatch::TestResponse . But the following line, which should work officially, does not work: page.should have_selector "div.some_class" The page object has the class Capybara::Session . In which cases do you have to use the response.body object and when

Rails 3 params unwanted wrapping

徘徊边缘 提交于 2019-12-28 11:53:53
问题 I'm posting some JSON like the JSON form of {:name => "hello"} to my Rails 3 controller ExampleController. Instead of getting params like: {:name => "hello"} I'm getting: {:name => "hello", :controller => "example", :action => "index", :example => {:name => "hello"} (Yes the JSON data appears twice! and action and controller are added) Any idea why ? 回答1: ActionController automatically does this for JSON requests so that you can easily pass the parameters into Example.create or @example

Form submitted twice, due to :remote=>true

牧云@^-^@ 提交于 2019-12-28 11:53:45
问题 My form submitted twice, after double checked, it was cause by ':remote=>true'. I removed it, my project works well. Who can show me why? And how to use ':remote=>true'? My ruby code: <%= form_tag(admin_product_group_product_scopes_path(@product_group), :remote => true, :id => 'new_product_group_form') do %> <% options = grouped_options_for_select( Scopes::Product::SCOPES.map do |group_name, scopes| [ t(:name, :scope => [:product_scopes, :groups, group_name]), scopes.keys.map do |scope_name|

How do I generate specs for existing controllers?

本秂侑毒 提交于 2019-12-28 11:50:09
问题 I have several controllers already set up. Now I want to start writing spec tests for them. Is there a command that generates the spec files automatically? I know rails does this for new resources, but I don't know if it does it for existing controllers/models too. 回答1: rails g rspec:controller ControllerName When it asks you to override the existing controller, type n . 回答2: There are two options. If you want an empty spec file, you could try with: rails g rspec:controller ControllerName Now

Rails select_tag with ajax action (Rails 3 and jQuery)

只愿长相守 提交于 2019-12-28 11:46:31
问题 I have the following select list. <%= select_tag "project_id", options_from_collection_for_select(@projects, "id", "title") %> When the user selects an option from the above list, the list below should be populated with values from database based on the above selection. <%= select_tag "version_id", options_from_collection_for_select(??project.versions??, "id", "title") %> I think i should make use of the onchange event, but i have no idea on how to use it. Someone help me please. Thanks! 回答1:

Changes in the form are not saved to database

自古美人都是妖i 提交于 2019-12-28 09:38:40
问题 I'm trying to add a date field to my form. I added bootstrap-datepicker-rails gem, all required css and javascript. When I choose the date in the calendar and click Save, it's not updated in the database. Here's the code of the form: = simple_form_for @model = f.input :date_last, :required => true, :input_html => { data: {behaviour: "datepicker"}}, :as => :string = f.button :submit, 'Save', :class => 'btn btn-primary' I think this might have to do with formats, but not sure where to look at.

Bind Ckeditor value to model text in angularjs and rails

杀马特。学长 韩版系。学妹 提交于 2019-12-28 07:59:31
问题 I want to bind ckeditor text to ng-model text My View <fieldset> <legend>Post to: </legend> <div class="control-group"> <label class="control-label">Text input</label> <div class="controls"> <div class="textarea-wrapper"> <textarea id="ck_editor" name="text" ng-model="text" class="fullwidth"></textarea> </div> <p class="help-block">Supporting help text</p> </div> </div> <div class="form-actions"> <button type="submit" class="btn btn-primary">Post</button> <button class="btn">Cancel</button>

How to reset Heroku app and re-commit everything?

旧城冷巷雨未停 提交于 2019-12-28 07:39:11
问题 I'm building an application which I'm also testing in Heroku. I ran into some problem today and had to rollback one commit in my local git repo, but Heroku now won't recognize my changes saying that "everything is up to date". So, running git push heroku master heroku responds with Everything up-to-date which isn't true. UPDATE: Things I've tried git push -f heroku master git push --force heroku master git push heroku +master git push --force heroku +master Did some changes in the source code

Return a grouped list with occurrences using Rails and PostgreSQL

雨燕双飞 提交于 2019-12-28 07:15:09
问题 I have a list of Tags in my rails application which are linked to Posts using Taggings . In some views, I'd like to show a list of the 5 most commonly used tags, together with the times they have been tagged. To create a complete example, assume a table with 3 posts: POSTS ID | title 1 | Lorem 2 | Ipsum 3 | Dolor And a table with 2 Tags TAGS ID | name 1 | Tag1 2 | Tag2 Now, if Post 1 is tagged with Tag1 and post 2 is tagged with tags 1 and 2, our taggings table looks like this: TAGGINGS tag