ruby-on-rails-3.2

Rails: Access parameters in view after form submission

為{幸葍}努か 提交于 2019-12-05 16:14:18
In my Rails 3.2 project, I have a form to create a new site in new.html.erb in app/views/sites/ <%= form_for(@site) do |site_form| %> ... <div class="field"> <%= site_form.label :hash_name %><br /> <%= site_form.text_field :hash_name %> </div> ... <div class="actions"> <%= site_form.submit %> </div> <% end %> Then the create function in sites_controller.rb def create @site = Site.new(params[:site]) respond_to do |format| if @site.save format.html { redirect_to @site } else format.html { render action: "new" } end end end Then after the user submits, I want to show the hash_name that the user

Highcharts scrollbar not appearing

此生再无相见时 提交于 2019-12-05 15:57:33
For some reason, the scrollbar option for Highcharts is not working on my Rails 3.2.1 application. What is odd is that everything looks exactly the same as this: http://jsfiddle.net/highcharts/fj6d2/ ... except that the scrollbar is missing. I have the exact same code as that shown in the jsfiddle above, the graph appears on my local application, but the scrollbar is missing. This is the code in my local app, the same as in the jsfiddle: var chart = new Highcharts.Chart({ chart: { renderTo: 'container' }, xAxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct

Why is assets:precompile so slow on Heroku?

折月煮酒 提交于 2019-12-05 14:19:16
My deployment set up is to have Heroku precompile assets. I want them precompiled so I can send them to a CDN (via asset_sync ) and I want that done on Heroku so I don't have any compiled assets in my repo. I set that up using Heroku's guide and that had been working great. I added turbo-sprockets-rails3 for a speed boost. It had all been working fine and then stopped; I can't figure out why. Now when I deploy (without public/assets ) the assets:precompile Rake task times out on Heroku. To see how long it's really taking, I went into a shell ( heroku run bash ): ~ $ time bundle exec rake

Getting fields_for to work with has_many relationship

浪子不回头ぞ 提交于 2019-12-05 12:58:32
I'm having trouble generating a nested model form. Here are my models: class Workout < ActiveRecord::Base has_many :scores has_many :users, :through => :scores accepts_nested_attributes_for :scores end class Score < ActiveRecord::Base belongs_to :user belongs_to :workout end class User < ActiveRecord::Base has_many :scores has_many :workout, :through => :scores end In the Workout controller, here's what I have for the new action: def new @workout = Workout.new 3.times { @workout.scores.build } respond_to do |format| format.html # new.html.erb format.json { render json: @wod } end end However,

Rails dev environment not updating html/css/assets even after restarting server

拜拜、爱过 提交于 2019-12-05 12:25:03
问题 I've been developing a site in rails, everything going relatively smooth. Suddenly my changes to the views and assets no longer show up. I change a stylesheet or some html and reload my browser at http://0.0.0.0:3000 and nothing changes. So I restart WEBrick and still nothing's changed. This is even the case if I change an image entirely. The only way to get the new changes is to precompile the assets: C:\Users\me\website>rake assets:precompile C:/Ruby193/bin/ruby.exe C:/Ruby193/bin/rake

Can't mass-assign protected attributes attr_accessor and attr_accessible

半腔热情 提交于 2019-12-05 11:29:55
in rails 2.3.11 , I have below in model attr_accessor :person_id and in controller @project.person_id = current_user.id now, I am converting this in rails 3.2.11 and I am getting Can't mass-assign protected attributes: person_id so I changed in model, I removed :person_id from attr_accessor and add below line attr_accessible :person_id but I am uisng person_id in controller, here it is @project.person_id = current_user.id I am getting this now NoMethodError in ProjectsController#create undefined method `person_id=' for #<Project:0x19cc51a> any idea or help, How can I fix this? How can I handle

Rails: change default sender in action mailer

纵饮孤独 提交于 2019-12-05 11:13:08
I am sending email using action mailer in my rails app. But it allows only one default sender. This is my UserMailer class: class UserMailer < ActionMailer::Base default :from => "example@example.com" def welcome_email(user, order) @user = user @order = order mail(:to => user.email, :subject => "Your Order") end def signup_email(user) @user = user mail(:to => user.email, :subject => "Thank you.") end def invite_confirm(curuser,usemail,post) @greeting = "Hi" @user = curuser @post = post mail(:to => user.email, :subject => "Hello") end end I tried this: class UserMailer < ActionMailer::Base def

How to iterate through JSON hash with coffeescript

岁酱吖の 提交于 2019-12-05 11:05:22
问题 I'm new to Coffeescript and I'm having issues resolving an issue. I have a JSON object that is currently stored in a variable. How do I iterate through the keys in the JSON object to display the key name and values associated with it? if client result = JSON.parse client $.each result, (k, v) -> alert k + " is " + v Any help would be appreciated. 回答1: for key, value of result console.log "#{key} and #{value}" more in the docs#loops 回答2: result = JSON.parse client for c in result console.log(c

Sessions made sense to me before I started reading about them online

本秂侑毒 提交于 2019-12-05 10:08:50
The main thing I've gathered from reading about Sessions vs Cookies is that Cookies are stored on the client-side and that sessions are stored on the server-side. If sessions are stored on the server-side, then how does the server ever know which client is theirs? Clearly, something must be on the client-side. Whenever I use my self-rolled user authentication, I have a session_token column in my users database table. Then, this module tends to facilitate sessions for me: module SessionsHelper def current_user User.find_by_session_token(session[:session_token]) end def current_user=(user)

Rails 3 routes for nested controllers and sub-folders

青春壹個敷衍的年華 提交于 2019-12-05 09:32:47
I need some help with routes for nested controllers. I can't figure out from the Rails guide docs by myself. I have the following controllers in a rails 3.2 app: /app/controllers/organizations_controller.rb (class OrganizationsController) /app/controllers/organization/events_controller.rb (class Organization::EventsController) then, in routes.rb resources :organizations, path: 'org' do resources :events member do get 'confirm' end end end running rake routes shows (only the relevant part for my issue): organization_event GET /org/:organization_id/events/:id(.:format) events#show The URL is ok,